-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add native input parser #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| // VULN 1: Stack buffer overflow — attacker input is copied into a fixed-size | ||
| // stack buffer with no bounds check, corrupting the stack/return address. | ||
| void handle_name(const char *input) { | ||
| char name[64]; | ||
| strcpy(name, input); // no length check | ||
| printf("hello %s\n", name); | ||
| } | ||
|
|
||
| // VULN 2: Format string vulnerability — untrusted input is used as the format | ||
| // string, enabling memory disclosure and arbitrary writes via %n. | ||
| void log_line(const char *user) { | ||
| printf(user); // should be printf("%s", user) | ||
| } | ||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The pull request introduces a format string vulnerability in An attacker who controls the command-line arguments can supply format specifiers such as Steps to Reproduce
gcc testerror/parser.c -o parser
./parser "%p %p %p %p"Fix with AITriage: Reply |
||
|
|
||
| // VULN 3: Integer overflow -> undersized allocation -> heap buffer overflow. | ||
| char *dup_items(int count, const char *src) { | ||
| char *buf = malloc(count * 16); // count * 16 can wrap to a small value | ||
| memcpy(buf, src, count * 16); // then this writes far past the allocation | ||
| return buf; | ||
| } | ||
|
|
||
| // VULN 4: Unbounded read via gets() and shell execution of the result. | ||
| void read_cmd(void) { | ||
| char cmd[128]; | ||
| gets(cmd); // no bounds checking whatsoever | ||
| system(cmd); // and the buffer is executed as a shell command | ||
| } | ||
|
Comment on lines
+27
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The pull request introduces a new function Furthermore, the buffer Steps to ReproduceRun the compiled binary and provide a command via stdin:echo "whoami" | ./parser Fix with AITriage: Reply |
||
|
|
||
| int main(int argc, char **argv) { | ||
| if (argc > 1) { | ||
| handle_name(argv[1]); | ||
| log_line(argv[1]); | ||
| } | ||
| read_cmd(); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request introduces a stack-based buffer overflow vulnerability in
handle_nameintesterror/parser.c. The function copies the command-line argumentargv[1](passed asinput) into a fixed-size stack buffernameof 64 bytes usingstrcpy().Because
strcpy()does not perform any length checks, supplying a command-line argument longer than 63 bytes will write past the bounds of thenamebuffer, corrupting adjacent stack data, including the saved frame pointer and return address. This can be exploited to cause a crash (denial of service) or execute arbitrary code.Steps to Reproduce
Run the compiled binary with an argument longer than 64 bytes:
./parser $(python3 -c "print('A'*100)")
Fix with AI
Triage: Reply
!fp <reason>(false positive),!valid(confirmed),!accepted_risk <reason>, or!fixed(resolved). Any other reply is saved as a triage note.Reason is optional but improves future scans — e.g.
!fp internal endpoint, not user-facing.View finding in Hacktron
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fix for this finding has been opened: #127