I'm sure if someone who's more knowledgeable about coding/cybersecurity in general they could printout a lot more data about the server that shouldn't have been there.
This happened when I was trying to do the assignment as usual, but this time I had difficulties (I'm a beginner) so I just kept slapping code on top of each other which kind of worked (somehow) but it also uncovered some "sensitive"? data with the cs50 servers.
looks like it is inside a K8S pod so past compromising the pod, it probably isn't going to achieve much. I doubt something like this has much stuff in the configmaps since it appears to be just invoking the encryption process as a subprocess from the shell within a container. Probably done to make scaling easier.
From the looks of it, you didn't stumble on anything significant. It looks like you just printed out the environment variables that the OS passed to your program. Also your program probably is running in a sandboxed environment, so you really can't do anything...
I'd say you're most likely correct about the environment being sandboxed. Especially if this is something hosted by the university. I'd be willing to be the lack of security is intentional as they may use this same code checker to teach cybersecurity students about different exploits and attack vectors.
That said, these aren't OS level environment variables. These variables come from the scripts used to start the K8s instance. In normal systems these should be inaccessible to anyone not logged into the actual server. If this was a production application used for something other than checking student code it could be a major issue depending on what the scripts look like.
Personally, I'd be impressed and likely give extra credit to any students who could explain what went wrong in the code to obtain this output and why that specific segment caused it if I were the professor.
The good thing is that my guess is as good as any freshman with no coding knowledge in what went wrong here. It's been ages since I've written any C code and never really took a deep dive into it.
The fact that the env is visible to the user of the service in any way is already telling enough about their security. There is probably DB credentials / connection string in there as well, which might have all the PII as well.
Not the issue tbh. His issue is assuming his char array is null terminated. Pass in 64+ chars and it will be non-null terminated. Then his second loop will continue until it blasts whatever memory it can.
Yes, that is indeed true, however you also should copy the string correctly ensuring it keeps being null terminated. That is correctly done by strcpy_s
I just explained the branch why it could leak env variables.
C is sketchy for security because it’s so easy to introduce an exploit on accident. You printed out the environment because this is how C do be when you overwrite a null terminator. Undefined behavior means your computer could become sentient and murder you in your sleep. It’s best to avoid undefined behavior. Luckily it just printed the environment.
It would be awesome if a course using C explained how the language works in context of the OS instead of just the syntax of C, but I guess that would be even more confusing, since C works on all sorts of OS, hardware, compiler combos.
139
u/Tsujigiriuwu Jan 25 '23 edited Jan 25 '23
I'm sure if someone who's more knowledgeable about coding/cybersecurity in general they could printout a lot more data about the server that shouldn't have been there.
This happened when I was trying to do the assignment as usual, but this time I had difficulties (I'm a beginner) so I just kept slapping code on top of each other which kind of worked (somehow) but it also uncovered some "sensitive"? data with the cs50 servers.
Mess in pastebin!
Edit: Spelling.
Edir2: https://pastebin.com/jWAtAcJT
33
u/Sanduhr32 Jan 25 '23
strncpy is unsafe here, argv[argc+2] should be the start of environment variables usually. You can easily drift into there by accident.
In the future please use strcpy_s :)
7
u/FloppyMonkey07 Jan 25 '23
I read CSGO, was very confused
6
u/okay-wait-wut Jan 26 '23
C is sketchy for security because it’s so easy to introduce an exploit on accident. You printed out the environment because this is how C do be when you overwrite a null terminator. Undefined behavior means your computer could become sentient and murder you in your sleep. It’s best to avoid undefined behavior. Luckily it just printed the environment.
It would be awesome if a course using C explained how the language works in context of the OS instead of just the syntax of C, but I guess that would be even more confusing, since C works on all sorts of OS, hardware, compiler combos.
1
u/oj_mudbone Jan 25 '23
Woah.
1
u/WhyYouLetRomneyWin Jan 26 '23
What am i looking at here?
0
u/[deleted] Jan 25 '23
[deleted] — view deleted comment