2014-12-17 4 views
0

이 스크립트를 python2에서 python3으로 변환하려고합니다.python 'decode'에는 특성 쉘 코드가 없습니다

이 '쉘 코드는'다음 줄에 ByteArray의로 변환 (또는해야한다) 도착
# need to code the input into the right format through string escape 
shellcode = shellcode.decode("string_escape") 

:

shellcode = bytearray(shellcode) 

그러나, 내가 실행

나는이 라인에 문제로 실행하고 의 오류로 :

AttributeError: 'str' object has no attribute 'decode'. 

"쉘 코드는"동일 :

shellcode = sys.argv[1] 

쉘 코드는 "\ x31 \ xd2 \ xb2 \ x30 \"과 같아야하고 나머지 스크립트는 쉘 코드를 실행해야합니다.

감사합니다 (이 스크립트는 python2.7에서 완벽하게 실행됩니다).

답변

4

python3에서 sys.argv [1]은 str (unicode, python2)이므로 디코딩 할 것이 없습니다.

간단한 테스트 - arg_type.py : python3 및 파이썬 2

$ python3.4 arg_type.py 'é' 
<class 'str'> 

$ python2.7 arg_type.py 'é' 
<type 'str'> 

주에서

import sys 
shellcode = sys.argv[1] 
print(type(shellcode)) 

실행 python2.7 str을 당신이 필요로하는 것 ByteArray의가, 정말입니다 유니 코드로 디코딩 할 수 있습니다.

이것은 python3이 기본적으로 더 현명한 방법 중 하나입니다.