“These courses expects a high standard of professionalism from its students with regard to how security testing is conducted. We expect all students to act in good faith at all times […]”
TL;DR Don’t be mean
Overall Submissions: 57 / 74
2-stack-dump 24 32%
2-simple 54 73%
2-shellz 44 59%
2-find-me 36 49%
Overall Submissions: 49 / 74
3-meme 47 64%
3-formatrix 44 59%
3-tetris 35 47%
3-elonmusk 26 35%
As of 2AM 22/06/2021
i += 1
i++
i & 1 == 0
i % 2
int main(int argc, char** argv) {
return;
}
int int_return() {
return;
}
int int_return0() {
return 0;
}
int int_return1() {
return 1;
}
void void_return() {
return;
}
python3
blah
./stack-dump
./stack-dump
fit() / flat()
elf.symbols[funcName]
int flags = 1;
if (flags & FLAG ) {
printf("TRUE\n");
} else {
printf("FALSE\n");
}
int flags = 1;
if (flags & FLAG != 0) { //
printf("TRUE\n"); // What could possibly go wrong?
} else { // works on my machine TM
printf("FALSE\n"); //
}
if (flags & (FLAG != 0)) {
printf("TRUE\n");
} else {
printf("FALSE\n");
}
Operation Precedence
flags = flags + 1 % 2;
printf("Flags: %d\n",flags);
(flags + 1) % 2;
flags + (1 % 2);
~ it be B 🐝
B for bee buzzz bug brrrrrrrrrr
char pt[] = "THISISSOMEDATAOFSOMESORT";
char env_script_name[] = "USER_CONTROLLED_ENV1";
char env_path_info[] = "USER_CONTROLLED_ENV2";
int ptlen = strlen(pt) - strlen(env_script_name);
int path_translated_len = ptlen + env_path_info ? strlen(env_path_info) : 0;
char *path_translated = NULL;
path_translated = (char *) malloc(path_translated_len + 1);
memcpy(path_translated, pt, ptlen);
if (env_path_info) {
memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen);
}
What’s wrong with this code?
int path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0);
if (env_path_info) {
path_translated_len = ptlen + strlen(env_path_info);
} else {
path_translated_len = ptlen;
}
if (ptlen + env_path_info) { // bit of a rip.
path_translated_len = strlen(env_path_info);
} else {
path_translated_len = 0;
}
int path_translated_len = (ptlen + env_path_info) ? strlen(env_path_info) : 0;
...
if (env_path_info) {
memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen);
}
ptlen = -env_path_info
path_translated_len = 0
path_translated_len - ptlen
0 - ptlen
-ptlen
… negative param in memcpy
?
int path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0);
____________________________
< Brackets people, brackets! >
----------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
:p ||----w |
|| ||
if (x == 0) {
if (y == 0) error();
else {
z = x + y;
fclose(&z);
}
if (x == 0){
if (y == 0)
error();
else {
z = x + y;
fclose(&z);
}
}
i = 0
while (i < n) {
y[i] = x[i++];
}
What will happen here?
The compiler decides
u_int strLen = strlen(userinput);
int buffsize = strLen + 11;
char *mem = malloc(buffsize);
strncpy(mem, "this/path/", 10);
strncpy(mem[10], userinput, strLen);
What can go wrong?
1 2 3 4 5 6 7 8 9 0 anddd iiii oooop!
char *var;
printf(var);
fprintf(stderr, var);
vsnprintf(var2, strlen(var2), var);
(Week 3 content)
char *var = malloc(10);
free(var);
printf("%s\n", var); // !!!!!
char *var = malloc(10);
free(var); // !!!!!
char *var2 = malloc(10);
free(var2);
free(var); // !!!!!
More on these later on!
char *a;
vuln_syscall_sets_a_NULL(a);
char b[] = "string";
strcpy(a, b); // strcpy(NULL, b);
Usually we would get a segfault…
But what if we did a memory map (mmap
)?
mem = mmap(NULL, 0x1000, PROT READ | PROT WRITE | PROT EXEC, MAP FIXED | MAP ANONYMOUS | MAP PRIVATE, 0, 0);
privilege escalation maybe?
char *var = malloc(10);
if (var == NULL) return;
for (int i = 0; i <= 10; i++) { // This will loop 11 times!
var[i] = argv[2][i];
}
Friday 2nd July
2 hour exam, open from 10am - 6pm
Practice!
DEBUG