2013년 3월 30일 토요일

pydbg(pydasm) with python 2.7.x or more (installation guide and fix way)


발로하는 영작은 이해해주세요.
Please understand that poor English composition.

system : windows x64
기존에 나와 있는 방법들로 설치를 하면 어려움이 있을 것이다.
다음 단계를 따르도록 하자.
There is a installing problem of pydbg with python. you should try following steps.


설치 파일 준비. -- ready for packages.
python-2.7.x.msi 파이썬
cygwin 시그윈
mingw-get-inst-20120426.exe 컴파일러
libdasm-1.5.tar.gz pydasm소스
openRCE-paimei-d78f574.7z pydbg 소스
그리고 홈페이지 내에 있는 pydbg파일 까지 받아 주세요.

우선 파이선 설치.
시그윈설치
mingw32설치

install 3 important packages.
python, cygwin, mingw32 compiler.



설치후 환경변수 등록. - after installation, you need to add Environment variable.
PATH
C:\Python;C:\MinGW\bin;C:\cygwin\bin

추가 - add NEW Environment variable 
PYTHONPATH
c:\python\lib;c:\python\Lib;


libdasm-1.5.tar.gz pydasm소스
openRCE-paimei-d78f574.7z pydbg 소스

OpenRCE-pydbg-292fff0.zip 파일은 openRCE-paimei-d78f574 폴더내의
pydbg폴더에다 압축을 푼다.
--extract these 3 source.


CMD를 실행한다.
--run the cmd shell. and type these codes.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\jihopark>cd Downloads

C:\Users\jihopark\Downloads>cd OpenRCE-paimei-d78f574

__build_installer.bat 를 실행하기전에 파일을 수정하여 파이썬 경로를 확인하도록 한다. 
--you need to check installed python location and modify __build_installer.bat file.

C:\Users\jihopark\Downloads\OpenRCE-paimei-d78f574>__build_installer.bat

C:\Users\jihopark\Downloads\OpenRCE-paimei-d78f574>REM $Id: __build_installer.ba
t 194 2007-04-05 15:31:53Z cameron $

C:\Users\jihopark\Downloads\OpenRCE-paimei-d78f574>c:\Python\python.exe setup.py
 bdist_wininst --bitmap=logos\installer.bmp --title=PaiMei
running bdist_wininst
running build
running build_py
installing to build\bdist.win32\wininst
running install_lib
creating build\bdist.win32
creating build\bdist.win32\wininst
creating build\bdist.win32\wininst\PURELIB
creating build\bdist.win32\wininst\PURELIB\pgraph
copying build\lib\pgraph\cluster.py -> build\bdist.win32\wininst\PURELIB\pgraph
copying build\lib\pgraph\edge.py -> build\bdist.win32\wininst\PURELIB\pgraph
copying build\lib\pgraph\graph.py -> build\bdist.win32\wininst\PURELIB\pgraph
copying build\lib\pgraph\node.py -> build\bdist.win32\wininst\PURELIB\pgraph
copying build\lib\pgraph\__init__.py -> build\bdist.win32\wininst\PURELIB\pgraph

creating build\bdist.win32\wininst\PURELIB\pida
copying build\lib\pida\basic_block.py -> build\bdist.win32\wininst\PURELIB\pida
copying build\lib\pida\defines.py -> build\bdist.win32\wininst\PURELIB\pida
copying build\lib\pida\function.py -> build\bdist.win32\wininst\PURELIB\pida
copying build\lib\pida\instruction.py -> build\bdist.win32\wininst\PURELIB\pida
copying build\lib\pida\module.py -> build\bdist.win32\wininst\PURELIB\pida
copying build\lib\pida\__init__.py -> build\bdist.win32\wininst\PURELIB\pida
creating build\bdist.win32\wininst\PURELIB\pydbg
copying build\lib\pydbg\breakpoint.py -> build\bdist.win32\wininst\PURELIB\pydbg

copying build\lib\pydbg\defines.py -> build\bdist.win32\wininst\PURELIB\pydbg
copying build\lib\pydbg\hardware_breakpoint.py -> build\bdist.win32\wininst\PURE
LIB\pydbg
copying build\lib\pydbg\memory_breakpoint.py -> build\bdist.win32\wininst\PURELI
B\pydbg
copying build\lib\pydbg\memory_snapshot_block.py -> build\bdist.win32\wininst\PU
RELIB\pydbg
copying build\lib\pydbg\memory_snapshot_context.py -> build\bdist.win32\wininst\
PURELIB\pydbg
copying build\lib\pydbg\my_ctypes.py -> build\bdist.win32\wininst\PURELIB\pydbg
copying build\lib\pydbg\pdx.py -> build\bdist.win32\wininst\PURELIB\pydbg
copying build\lib\pydbg\pydasm.pyd -> build\bdist.win32\wininst\PURELIB\pydbg
copying build\lib\pydbg\pydbg.py -> build\bdist.win32\wininst\PURELIB\pydbg
copying build\lib\pydbg\pydbg_client.py -> build\bdist.win32\wininst\PURELIB\pyd
bg
copying build\lib\pydbg\system_dll.py -> build\bdist.win32\wininst\PURELIB\pydbg

copying build\lib\pydbg\windows_h.py -> build\bdist.win32\wininst\PURELIB\pydbg
copying build\lib\pydbg\__init__.py -> build\bdist.win32\wininst\PURELIB\pydbg
creating build\bdist.win32\wininst\PURELIB\utils
copying build\lib\utils\code_coverage.py -> build\bdist.win32\wininst\PURELIB\ut
ils
copying build\lib\utils\crash_binning.py -> build\bdist.win32\wininst\PURELIB\ut
ils
copying build\lib\utils\hooking.py -> build\bdist.win32\wininst\PURELIB\utils
copying build\lib\utils\injection.py -> build\bdist.win32\wininst\PURELIB\utils
copying build\lib\utils\process_stalker.py -> build\bdist.win32\wininst\PURELIB\
utils
copying build\lib\utils\udraw_connector.py -> build\bdist.win32\wininst\PURELIB\
utils
copying build\lib\utils\__init__.py -> build\bdist.win32\wininst\PURELIB\utils
running install_egg_info
Writing build\bdist.win32\wininst\PURELIB\PaiMei-1.2-py2.7.egg-info
creating 'c:\users\jihopark\appdata\local\temp\tmpuywfj1.zip' and adding '.' to
it
adding 'PURELIB\PaiMei-1.2-py2.7.egg-info'
adding 'PURELIB\pgraph\cluster.py'
adding 'PURELIB\pgraph\edge.py'
adding 'PURELIB\pgraph\graph.py'
adding 'PURELIB\pgraph\node.py'
adding 'PURELIB\pgraph\__init__.py'
adding 'PURELIB\pida\basic_block.py'
adding 'PURELIB\pida\defines.py'
adding 'PURELIB\pida\function.py'
adding 'PURELIB\pida\instruction.py'
adding 'PURELIB\pida\module.py'
adding 'PURELIB\pida\__init__.py'
adding 'PURELIB\pydbg\breakpoint.py'
adding 'PURELIB\pydbg\defines.py'
adding 'PURELIB\pydbg\hardware_breakpoint.py'
adding 'PURELIB\pydbg\memory_breakpoint.py'
adding 'PURELIB\pydbg\memory_snapshot_block.py'
adding 'PURELIB\pydbg\memory_snapshot_context.py'
adding 'PURELIB\pydbg\my_ctypes.py'
adding 'PURELIB\pydbg\pdx.py'
adding 'PURELIB\pydbg\pydasm.pyd'
adding 'PURELIB\pydbg\pydbg.py'
adding 'PURELIB\pydbg\pydbg_client.py'
adding 'PURELIB\pydbg\system_dll.py'
adding 'PURELIB\pydbg\windows_h.py'
adding 'PURELIB\pydbg\__init__.py'
adding 'PURELIB\utils\code_coverage.py'
adding 'PURELIB\utils\crash_binning.py'
adding 'PURELIB\utils\hooking.py'
adding 'PURELIB\utils\injection.py'
adding 'PURELIB\utils\process_stalker.py'
adding 'PURELIB\utils\udraw_connector.py'
adding 'PURELIB\utils\__init__.py'
removing 'build\bdist.win32\wininst' (and everything under it)

또는 아래와 같이 직접적으로 빌드와 인스톨을 해준다.
or use this way.
i recommend this.

C:\Users\jihopark\Downloads\OpenRCE-paimei-d78f574>python setup.py build
running build
running build_py

C:\Users\jihopark\Downloads\OpenRCE-paimei-d78f574>python setup.py install
running install
running build
running build_py
running install_lib
creating C:\Python\Lib\site-packages\pgraph
copying build\lib\pgraph\cluster.py -> C:\Python\Lib\site-packages\pgraph
copying build\lib\pgraph\edge.py -> C:\Python\Lib\site-packages\pgraph
copying build\lib\pgraph\graph.py -> C:\Python\Lib\site-packages\pgraph
copying build\lib\pgraph\node.py -> C:\Python\Lib\site-packages\pgraph
copying build\lib\pgraph\__init__.py -> C:\Python\Lib\site-packages\pgraph
creating C:\Python\Lib\site-packages\pida
copying build\lib\pida\basic_block.py -> C:\Python\Lib\site-packages\pida
copying build\lib\pida\defines.py -> C:\Python\Lib\site-packages\pida
copying build\lib\pida\function.py -> C:\Python\Lib\site-packages\pida
copying build\lib\pida\instruction.py -> C:\Python\Lib\site-packages\pida
copying build\lib\pida\module.py -> C:\Python\Lib\site-packages\pida
copying build\lib\pida\__init__.py -> C:\Python\Lib\site-packages\pida
creating C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\breakpoint.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\defines.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\hardware_breakpoint.py -> C:\Python\Lib\site-packages\py
dbg
copying build\lib\pydbg\memory_breakpoint.py -> C:\Python\Lib\site-packages\pydb
g
copying build\lib\pydbg\memory_snapshot_block.py -> C:\Python\Lib\site-packages\
pydbg
copying build\lib\pydbg\memory_snapshot_context.py -> C:\Python\Lib\site-package
s\pydbg
copying build\lib\pydbg\my_ctypes.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\pdx.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\pydasm.pyd -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\pydbg.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\pydbg_client.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\system_dll.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\windows_h.py -> C:\Python\Lib\site-packages\pydbg
copying build\lib\pydbg\__init__.py -> C:\Python\Lib\site-packages\pydbg
creating C:\Python\Lib\site-packages\utils
copying build\lib\utils\code_coverage.py -> C:\Python\Lib\site-packages\utils
copying build\lib\utils\crash_binning.py -> C:\Python\Lib\site-packages\utils
copying build\lib\utils\hooking.py -> C:\Python\Lib\site-packages\utils
copying build\lib\utils\injection.py -> C:\Python\Lib\site-packages\utils
copying build\lib\utils\process_stalker.py -> C:\Python\Lib\site-packages\utils
copying build\lib\utils\udraw_connector.py -> C:\Python\Lib\site-packages\utils
copying build\lib\utils\__init__.py -> C:\Python\Lib\site-packages\utils
byte-compiling C:\Python\Lib\site-packages\pgraph\cluster.py to cluster.pyc
byte-compiling C:\Python\Lib\site-packages\pgraph\edge.py to edge.pyc
byte-compiling C:\Python\Lib\site-packages\pgraph\graph.py to graph.pyc
byte-compiling C:\Python\Lib\site-packages\pgraph\node.py to node.pyc
byte-compiling C:\Python\Lib\site-packages\pgraph\__init__.py to __init__.pyc
byte-compiling C:\Python\Lib\site-packages\pida\basic_block.py to basic_block.py
c
byte-compiling C:\Python\Lib\site-packages\pida\defines.py to defines.pyc
byte-compiling C:\Python\Lib\site-packages\pida\function.py to function.pyc
byte-compiling C:\Python\Lib\site-packages\pida\instruction.py to instruction.py
c
byte-compiling C:\Python\Lib\site-packages\pida\module.py to module.pyc
byte-compiling C:\Python\Lib\site-packages\pida\__init__.py to __init__.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\breakpoint.py to breakpoint.pyc

byte-compiling C:\Python\Lib\site-packages\pydbg\defines.py to defines.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\hardware_breakpoint.py to hardw
are_breakpoint.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\memory_breakpoint.py to memory_
breakpoint.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\memory_snapshot_block.py to mem
ory_snapshot_block.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\memory_snapshot_context.py to m
emory_snapshot_context.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\my_ctypes.py to my_ctypes.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\pdx.py to pdx.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\pydbg.py to pydbg.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\pydbg_client.py to pydbg_client
.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\system_dll.py to system_dll.pyc

byte-compiling C:\Python\Lib\site-packages\pydbg\windows_h.py to windows_h.pyc
byte-compiling C:\Python\Lib\site-packages\pydbg\__init__.py to __init__.pyc
byte-compiling C:\Python\Lib\site-packages\utils\code_coverage.py to code_covera
ge.pyc
byte-compiling C:\Python\Lib\site-packages\utils\crash_binning.py to crash_binni
ng.pyc
byte-compiling C:\Python\Lib\site-packages\utils\hooking.py to hooking.pyc
byte-compiling C:\Python\Lib\site-packages\utils\injection.py to injection.pyc
byte-compiling C:\Python\Lib\site-packages\utils\process_stalker.py to process_s
talker.pyc
byte-compiling C:\Python\Lib\site-packages\utils\udraw_connector.py to udraw_con
nector.pyc
byte-compiling C:\Python\Lib\site-packages\utils\__init__.py to __init__.pyc
running install_egg_info
Writing C:\Python\Lib\site-packages\PaiMei-1.2-py2.7.egg-info


이렇게 pydbg가 설치가 되었다. 하지만 실행해 보면 아래와 같은 오류가 날 것이다.
ok done. but it will be dosen't work. this problem is the old and wrong pydadm file. this file occur dll load fail.


>>> import pydbg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python\lib\site-packages\pydbg\__init__.py", line 47, in <module>
    from pydbg                   import *
  File "C:\Python\lib\site-packages\pydbg\pydbg.py", line 32, in <module>
    import pydasm
ImportError: DLL load failed: 지정된 모듈을 찾을 수 없습니다.


이러한 오류를 바로 잡아야 겠다.
pydasm의 파일 문제로 인해 설치가 힘든것이었다. 이파일을 컴파일 하여 설치를 해야 한다.

you need to fix. we will make and compile pydasm with mingw32.


C:\Users\jihopark\Downloads>cd libdasm-1.5

C:\Users\jihopark\Downloads\libdasm-1.5>cd pydasm

C:\Users\jihopark\Downloads\libdasm-1.5\pydasm>python setup.py build
running build
running build_ext
building 'pydasm' extension
error: Unable to find vcvarsall.bat

설치를 하려하면 위와 같은 오류가 난다. 이는 pydasm파일이c로 작성되어 있기 때문이다. 이를
컴파일해보자.
mingw32를 이용하면 되겠다.
when you try to install. the fuxxing error occur. you need to add compile code.

C:\Users\jihopark\Downloads\libdasm-1.5\pydasm>python setup.py build -c mingw32
running build
running build_ext
building 'pydasm' extension
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python\include -IC:\Python\
include -IC:\Python\PC -c ../libdasm.c -o build\temp.win32-2.7\Release\..\libdas
m.o
cc1.exe: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1


컴파일을 실행했을 때 만약 이러한 오류가 난다면
파이썬프로그램의 py파일을 수정해야 한다.
when you try to compile. you can see this error. you need to fix cygwinccompiler.py.




 오류가 나는 부분은 -mno-cygwin 이라는 부분이다. 이 부분을 지워버려라.
error occur parts is there. --mno-cygwin. replace to blanks.
지우고 저장 후 컴파일을 수행한다.

and try compile.

C:\Users\jihopark\Downloads\libdasm-1.5\pydasm>python setup.py build -c mingw32
running build
running build_ext
building 'pydasm' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python\include -IC:\Python\include -IC:
\Python\PC -c ../libdasm.c -o build\temp.win32-2.7\Release\..\libdasm.o
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python\include -IC:\Python\include -IC:
\Python\PC -c pydasm.c -o build\temp.win32-2.7\Release\pydasm.o
writing build\temp.win32-2.7\Release\..\pydasm.def
creating build\lib.win32-2.7
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\..\libdasm.o build\
temp.win32-2.7\Release\pydasm.o build\temp.win32-2.7\Release\..\pydasm.def -LC:\
Python\libs -LC:\Python\PCbuild -lpython27 -lmsvcr90 -o build\lib.win32-2.7\pyda
sm.pyd

빌드를 성공했다.
ok success.


이번엔 설치를 할 차례이다.
and this time is your installation time.


C:\Users\jihopark\Downloads\libdasm-1.5\pydasm>python setup.py install
running install
running build
running build_ext
running install_lib
copying build\lib.win32-2.7\pydasm.pyd -> C:\Python\Lib\site-packages
running install_egg_info
Writing C:\Python\Lib\site-packages\pydasm-1.5-py2.7.egg-info

파일이 생성되었다. 
success!! you can meet the pydadm.


이 생성된 pydasm.pyd파일을 pydbg에다 넣어 주도록 한다. 안넣어 줘도 되긴 하지만 윈도우7에서는 넣어줘야 잘 실행 되었다.
well done. if you see the same error. you need copy the file and paste to the pydbg folder.



이제는 오류가 나지 않는다.
pydbg를 성공적으로 임포트 하였다.



ps ..
만약
ctypes 부분에서 오류가 난다면  C:\Python\Lib\ctypes\__init__.py 를 수정해야 한다.
if you occur the error on ctypes. need to fix following code.




from _ctypes import Structure as _ctypesStructure

from struct import calcsize as _calcsize <- 오리지날 original

class Structure (_ctypesStructure): pass


굵은 부분을 추가하도록 하자.


추가--
pydasm 파일이 컴파일 안되는 경우가 있어파일을 공유합니다.

pydsam파일

참고한 사이트
1. http://louppen.wordpress.com/2011/06/22/installing-the-sulley-fuzzer-framework-on-windows-xp-professional-the-trial-and-error-way/
2. http://code.google.com/p/paimei/issues/detail?id=3

댓글 없음:

댓글 쓰기