>What's the deadly bug here, Jow Forums? Writing a program in C.
Gavin Scott
>implying C is not the language of gods the absolute state of Jow Forums
Nolan Reed
I'm not reading you shit code faggot.
Blake Foster
Where do I even start. No input validation whatsoever. Using scanf period. No default: in the switch block. Use after free. Didn't even read what's happening in the functions, main is a clusterfuck already.
Kevin Barnes
>scanf("%d")
Why are you trying to show off here if you can't even capture user input properly?
Jace Williams
Dude, this is some disgusting code. What makes it really disgusting is that you're flexing it here. Are you seriously proud of this?
There isn't a sophisticated bug or exploit here. YOUR ENTIRE PROGRAM IS THE "DEADLY BUG" OR "EXPLOIT".
Jayden Jackson
It's dogshit. Proof is in the OP.
Hudson Young
what's the better option here? I honestly haven't used C in ages
even though that's not the point
Levi Rogers
OP's just not god but an ordinary faggot.
Jose Anderson
You have to be a god of faggots to use C.
Leo Evans
Not doing your homework :)
Joseph Adams
b-but it's supposed to be bad, user i think you're missing the point
Lincoln Watson
fix your own shit
David Peterson
I am not OP, I just don't see anything particularly bad about the code, except for maybe mixing different I/O functions needlessly or calling fflush needlessly. Is it muh globals?
Brody Stewart
Add a note. Delete a note. Print all notes. Be amazed.
Christian Jackson
the fflush is actually needed, since the stdout buffer is not guaranteed to flush without a newline or an explicit flush
exploit it fgt
Ryan Rogers
Ah I see it now, he isn't changing the NumOfNotes after deletion at all Then you should probably reformat your output, function calls are expensive
Andrew Campbell
>Ah I see it now, he isn't changing the NumOfNotes after deletion at all It's even worse, even if he did decrease it it would still crash.
Gabriel Hernandez
numOfNotes wouldn't really change anything, you'd still have the bug
function calls are not that expensive, it's literally a non issue most of the times
Colton Foster
It literally doesn't crash mose of the time unless you double free, I guess
Angel Jackson
Well what he would have to do is decrease the NumOfNotes while moving all later notes to the left I suppose(to not have unallocated holes), or just use a linked list. On the function calls part, while they are not that expensive, it's still better to not have unnecessary calls for overall performance.
Christian Cruz
> if (noteNum < numOfNotes){ printf("Deleting %d\n", noteNum); free(notes[noteNum]); }
You only free the memory associated with the note, you don't actually delete the note from the array.
Additionally, since you're allocating the memory separately instead of just having a by-value array, there's no telling where the note actually was in memory before you freed it.
It may be possible for an attacker to claim the freed memory and populate the path field with whatever they want, thus allowing them to use your program to view or overwrite any file their user account has the privilege to access, as long as either its absolute path or its path relative to the working directory is less than 50 characters long. Additionally, they could access files with longer paths by allocating more memory than was freed.
I don't think this is actually realistic, since on any operating system I know of, the system will pre-allocate all the memory your program can access, and the actual runtime allocator just operates over that memory space, not the full memory space of the computer; as such, running programs can't access each other's data, even in situations like this. I guess the attacker could prepopulate the memory from a different program, close that program to free its entire memory space, and then run your program and hope the memory they populated isn't reinitialized.
Cooper Ortiz
>it's still better to not have unnecessary calls define unnecessary? it's literally a non issue, especially in C function calls are literally just a few instructions not that the fflush is unnecessary either
Connor Davis
You got pretty much all of it right, except the last part.
i'm not sure why you think it's not enough of a vulnerability having an arbitrary read access? sure, the process lives in it's own virtual space in isolation, but that wasn't really the point
>I guess the attacker could prepopulate the memory from a different program, close that program to free its entire memory space, and then run your program and hope the memory they populated isn't reinitialized.
The virtual memory isn't shared by other processes at all, I don't think that could ever possibly work
Parker Hughes
>The virtual memory isn't shared by other processes at all Not by other running processes, sure, but do you mean to tell me it's not even shared by processes that are no longer running? Because if that's the case, that sounds like a pretty egregious OS-level memory leak????
Landon Foster
>typedef struct note{ > char name[50]; > char path[50]; >} note; >note* notes[100]; >char numOfNotes = 0; Why do I cringe every time I see a piece of C code? They are unsophisticated, arbitrarily restricted and very poorly written.
Camden Thompson
I think I'm missing your point, user.
Yes, I'm saying the /virtual/ memory is not shared by processes whatsoever, except when shared memory is explicitly used The stack is not shared and the heap is not shared I'm not sure about the static and global variables in, but I'm guessing they aren't either
The /virtual/ memory on the heap is presented as a zeroed out region, containing no data except some malloc and free metadata
and I'm not sure how not sharing the memory between processes constitutes as a memory leak
Robert Taylor
>The /virtual/ memory on the heap is presented as a zeroed out region, I see. I get you. This answers my question. If it's zeroed out first, nothing can be done.
It's not that sharing memory between processes constitutes a memory leak, I actually meant the opposite, I was just saying that if a process running now can't share memory with a process that was running before but now isn't, then all the user space memory would fill up in no time because old memory can't be reassigned to new processes.
But if a process running now CAN share memory with a process that was running before but now isn't, then, my thinking, which I now know is not quite right, was that you could use another program, write your string in it, close it, and then start OP's program and hope its virtual memory corresponds to the physical userspace memory that the OS just freed, and then the string you want would still be in that memory. But if the memory is zeroed first, the string would be gone anyway.
Jacob Wright
They're all avoiding the question because they're all LARPers who don't actually program.
PS: ur code is bad.
Gavin Reyes
This
It isn't elitist to use bullshit tools if you don't have to. I'm good enough at what I do to get a job that doesn't revolve around fixing bugs that don't have to exist
Jaxson Bennett
It's fast because we have compilers for it that have existed and been optimized for decades.
anyway it's more than that, it's also because C's semantics are closer to how the computer and operating system actually work than the semantics of most other languages used today
Thomas Miller
C is just really fast and memory efficient and thats why it's still so widely used it's also quite low level and let's you have more control over your program (for better or for worse) not to mention many other languages still use libc as a base
Samuel Wright
fpbp
Ian Gomez
Can someone please explain or point me in the right direction concerning
note* notes[100]
Caleb Reyes
Probably fgets() to avoid overflows
Logan Hughes
An array of 100 pointers, each to a note struct.
Julian Barnes
Why are you inconsistent on where you place the *?
C's switch statement has nothing on Rust's match expression.
Hunter Wright
It's true though, C's semantics fundamentally don't require as much abstraction to implement.
Dominic Harris
No, it's still elitist if your attitude about it is that you think the bullshit tools you use are marks of status.
I think what you mean is, it isn't *elite*. You can be elitist without your elitism being founded in reality.
Elijah Turner
What version of GLibC? I am guessing heap exploit by the looks of it. Compile flags? ASLR?
Owen Hall
You can forge a note by deleting and having the first note have the forged contents, then viewing that note. You could read arbitrary files. Are we going for shell?
Joseph Perry
>create a struct which is a variable that holds other variables >assign a variable to that variable >create an array of addresses that contain the possible future addresses that future instances of each struct variable may need
This isn't practical for most programs, specially for a program that simply stores string (oh sorry ARRAYS OF CHARS). We already figured that out years ago and abstracted that micromanagement bullshit out of the way, but the spergs on Jow Forums keep writing stupidly simple programs on C and shilling C here because they want to feel purists and feel like hax0rs I don't fucking know.
If you're not writing firmware or drivers or some other specific thing you have no business using C. I doubt anyone who browses Jow Forums writes firmware.
>it's also because C's semantics are closer to how the computer and operating system actually work
no it's just a language that was made when hardware limitations where incredibly strict so you had to micromanage every single byte you had it was good for the time and now it's just vaporware or it's used for programs that have to operate under severe memory limitations (which is getting rarer and rarer)
if it's so cool to talk to the machines who not write assembler? that is as elite hacker machine interface as you can get
David Jackson
C is high-level enough to use comfortably, assembly isn't.
Matthew Hughes
this OP is a massive faggot as per usual
Hudson Lopez
It's a programming challenge. It's common for capture the flag events and for wargaming and challenge websites. The fact that anyone would respond to OP posting a challenge with anger or negativity only shows how ignorant you are.
I'm sure you would rather be posting in some "totally organic" thread about some consumer product that has a bait topic to incite conversation about a company. Sad.
Tyler Gutierrez
well this is Jow Forums rarely anything constructive happens here
Andrew Sanchez
Sure, buddy. Keep saying that in your broken English until it is true.
Cooper Young
what's broken about it friend?
Jaxon Sanders
Can’t you create a file within that directory that is super long and contains a NOP sled?
Lincoln Roberts
why would you want to fix it? the more bugs, the better
Brandon Stewart
>Your entire code is ze bug Ding! Ding! Ding!
Josiah Cook
Nice code, thanks, I will be stealing it for my projects.
Ian Morales
>What's the deadly bug here, Jow Forums? Where do I start.. Buffer overflow Not checking file scamf no input checking
Oh god... Your code couldn't be more retarded: 1-: A lot of magic numbers that may overflow, as they don't grow as necessary (so why even using heap, instead of stack) 2-: Assuming safe input 3-: Not checking malloc 4-: Storing paths, instead of fd's 5-: Not removing the files when they are uneeded 6-: Resource leak This has zero safety consideration, any "main" exploit is just another one in an ocean of possible exploits
Liam Bennett
More fun is using heap when you have zero intention of accepting any buffer size.
Colton Clark
>integer overflow not exploitable here >assuming safe input not exploitable here >not checking malloc not exploitable here are you even trying right now?
and again, /bad/ code is the point of an intentionally exploitable program i still haven't seen a working exploit, user
Blake Brooks
using C is the issue
Charles Thomas
> Memory corruption isn't exploitable Imagine being this much of a brainlet
> /bad/ code is the point of an intentionally exploitable program t. brainlet that couldn't write non-retarded code with the exploit
Luke Perez
This is an entry level challenge from hackthebox and the absolute faggot that is OP wants you to solve it for him. The code is supposed to be bad.
Jace Bailey
holy shit imagine coping this much because you can't exploit babbys first vuln
>>not checking malloc imagine actually thinking this is memory corruption oh god
Aiden Gray
> imagine coping this much because you can't exploit babbys first vuln t. retard that thinks that this code has only one way of being exploited
> imagine actually thinking this is memory corruption t. brainless retard that don't know what memory corruption means nor what points i cited cause them
Jayden Hughes
>The code is supposed to be bad. Having multiple exploits discard any sense in searching for a specific one, undefined behaviour and memory corruption usually causes a lot of real problems when happens in real world
Gavin Moore
>scanf That's literally the first thing they tell you not to use. You're not l33t hacker you absolute fag.
Michael White
i'm sorry, user, but t. statements are not arguments in the slightest you still haven't posted not even one of the supposed "many" exploits here
there may be multiple possible vulnerabilities, but literally only one vuln that you could practically exploit an exploit is not the same thing as a possible vuln undefined behaviour, possible slight memory corruption and other things are just possible vulns, if you don't actually have a practical way of exploiting them
Jace Garcia
>using scanf for inputting numbers is bad ok user, if that's what they thought you in school go with it
Evan Garcia
so many options to choose from... i give up, cant decide on one.
Luke Martin
>usually show how exactly, not just repeat blanket statements your pajeet tier tutorials told you every retard can point out "oh this piece of code isn't 100% safe", it's called valgrind
Landon Gomez
Of course you, as a brainlet with severe dementia, isn't able to understand what being "vulnerable" means, and as such couldn't specify what type of vulnerability you expect. (in here you have data exposition, memory corruption (that have undefined results), races-condition)
t. brainless retarded, that thinks that is not a pajeet > heartbleed was only a buffer overflow (memory corruption) > lots of permission escalation are only races