ex:vcode:start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ex:vcode:start [2023/03/09 06:40] – titannet | ex:vcode:start [2023/07/31 05:51] (current) – titannet | ||
|---|---|---|---|
| Line 16: | Line 16: | ||
| } | } | ||
| - | < | + | </code> |
| ====== Stack 1 ====== | ====== Stack 1 ====== | ||
| - | + | <file example1.c | |
| - | <code c> | + | |
| #include < | #include < | ||
| #include < | #include < | ||
| Line 27: | Line 26: | ||
| - | char buffer[50]; | + | char buffer[20]; |
| int copy_buffer(char *input_buffer) { | int copy_buffer(char *input_buffer) { | ||
| Line 53: | Line 52: | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | ===== Walkthrough Windbg ===== | ||
| + | |||
| + | <code bash> | ||
| + | cl.exe /Zi /GS- /EH- | ||
| + | # debugging symbols, no stack security, no seh (not working??) | ||
| + | |||
| + | bp $exentry (if no symbols) | ||
| + | bp example1!main | ||
| + | # F5 | ||
| + | # debug -> make sure that source mode is unchecked | ||
| + | |||
| + | # x86 calling convention: parameter 1-3 on stack | ||
| + | # x86 function prolog: push ebp, mov ebp, esp | ||
| + | # [ebp+8] == local variable | ||
| + | |||
| + | # dd esp -> first address on stack == return pointer | ||
| + | # dd ebp -> old base pointer | ||
| + | # dd poi(ebp+8) | ||
| + | |||
| </ | </ | ||
| + | |||
| Line 120: | Line 141: | ||
| + | </ | ||
| + | ====== Heap2-2 ====== | ||
| + | |||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Use after free example, original code from https:// | ||
| + | |||
| + | #define SERVICE_SIZE 32 | ||
| + | |||
| + | struct AuthStruct { | ||
| + | char name[32]; | ||
| + | int is_authenticated; | ||
| + | }; | ||
| + | |||
| + | struct AuthStruct *auth; | ||
| + | char *service; | ||
| + | |||
| + | int main(int argc, char **argv) | ||
| + | { | ||
| + | char line[128]; | ||
| + | |||
| + | while(1) { | ||
| + | printf(" | ||
| + | if(fgets(line, | ||
| + | | ||
| + | if(strncmp(line, | ||
| + | auth = malloc(sizeof(*auth)); | ||
| + | memset(auth, | ||
| + | if(strlen(line + 5) < 31) { | ||
| + | strcpy(auth-> | ||
| + | } | ||
| + | } | ||
| + | if(strncmp(line, | ||
| + | free(auth); | ||
| + | } | ||
| + | if(strncmp(line, | ||
| + | service = malloc(SERVICE_SIZE); | ||
| + | strcpy(service, | ||
| + | } | ||
| + | if(strncmp(line, | ||
| + | if(auth-> | ||
| + | printf(" | ||
| + | } else { | ||
| + | printf(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| </ | </ | ||
ex/vcode/start.1678340444.txt.gz · Last modified: 2023/03/09 06:40 by titannet
