Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
05-15 13:20
관리 메뉴

nomad-programmer

[Programming/Python] 코드 난독화(obfuscation) / Source Code 보호 본문

Programming/Python

[Programming/Python] 코드 난독화(obfuscation) / Source Code 보호

scii 2019. 12. 23. 21:41

Python, C#, JavaScript 등은 쉽게 소스로 환원 시킬 수 있기 때문에 원 소스 자체의 로직은 변경되지 않지만 사람이 읽기에 아주 어렵게하는 것이 난독화라고 한다.
또한, 소스코드의 무단 도용, 아이디어나 알고리즘의 무단유출을 막기 위함이 주된 목적이라 할 수 있다.

JavaScript 같은 경우에는 악성코드나 시그니쳐 등을 회피하기 위해 난독화 기법을 이용한다.

 

코드 난독화는 크게 보았을 때, 필요 이상으로 복잡한 코드를 만들거나 무의미한 코드를 삽입하여 난독화하는 방법과 데이터를 인코딩하여 가독성을 떨어트리는 방법이 있다.

C언어 소스코드를 대상으로 코드 내에서 사용 중인 변수의 이름을 바코드 조합('l', 'i', 'I', '1'의 조합)으로 바꾸어 코드를 난독화 시킨다. 코드 내의 변수명이 "ilI1IlIil", "IiIIll1lIiiI"와 같은 방식의 이름으로 이루어져 있다면, 각각의 변수를 구분하기 정말 힘들것이다. 설령 파악한다고하더라도 해당 변수가 어떤 역할을 하는지 변수명을 통한 유추를 막을 수 있다.

난독화 원리는 코드를 단어별로 분리하여 변수를 바코드 조합으로 변경한 후, 단어를 다시 이어 붙인다.


온라인상으로 난독화할 수 있는 사이트

Oxyry Python Obfuscator

https://pyob.oxyry.com/

 

Oxyry Python Obfuscator - The most reliable python obfuscator in the world

Features Rename symbol names, includes variables, functions, classes, arguments, class private methods. The name replacer avoids a 1:1 mapping of cleartext names to obfuscated names, the same name may be converted to several different names within differen

pyob.oxyry.com

Python 난독화 사이트

Oxyry 에서 만든 난독화 사이트이다. 소스코드를 붙여넣기하면 그 즉시 난독화 해준다. 왼쪽 화면처럼 코딩된 코드의 경우 우측의 난독화 결과물을 잘 받아볼 수 있다. 하지만 짧고 간결한 소스의 경우는 난독화가 진행되지 않을 수 있다.


DevelopmentToolsNet

development-tools.net/python-obfuscator/

 

Development Tools - Python obfuscation

Does this tool store my original source code anywhere? This tool DOES NOT store your original source code anywhere, but it does store you obfuscated code until you have downloaded it or 5 minutes if no download activity has been detected.

development-tools.net

Python 난독화 사이트

DevelopmentToolsNet에서 만든 파이썬 코드 난독화 사이트이다. 파일 업로드하는 형태로 파이썬 파일 업로드 후 Obfuscate 버튼을 누르면 난독화된 파일이 그 즉시 나오게된다. 이 사이트의 경우 짧고 간결한 파이썬 코드도 난독화가 된다. 
이 사이트에서는 다운로드 기능을 제공하고 있는데 동작이 잘 안될수도 있다. 그래서 만약 아직까지도 그런다면 다운로드 링크 부분에서 우측 클릭 후 저장하거나 새 탭열기로 소스 코드를 복사하면 된다.


난독화 파이썬 모듈 및 난독화 방법

파이썬 소스 난독화 방법

https://www.smallsurething.com/how-to-obfuscate-python-source-code/

 

How to obfuscate Python source code - Learn How to Code and Make Games in Python

A lot of the Python code you will come across is open source. The whole point is to distribute it freely, share knowledge and let people play around with it and learn from it. Sometimes, though, you might want to prevent the end-user from reading the code.

www.smallsurething.com


난독화 모듈

https://github.com/astrand/pyobfuscate

 

astrand/pyobfuscate

pyobfuscate. Contribute to astrand/pyobfuscate development by creating an account on GitHub.

github.com


https://liftoff.github.io/pyminifier/

 

pyminifier - Minify, obfuscate, and compress Python code — pyminifier 2.1 documentation

So let’s pretend for a moment that your intentions are not pure; that you totally want to mess with the people that look at your minified code. What you need is Python 3 and the --nonlatin option... Yes, that code actually works but only using Python 3. Th

liftoff.github.io

pyminifier가 제일 쓸만한 듯 하다. 그리고 Python2 에서 이 모듈을 사용한다면... 난독화한 코드를 아웃풋 파일로 만들때 TypeError를 만날 것이다. 이런 경우 아래의 명령으로 업데이트해준다.

pip install git+https://github.com/liftoff/pyminifier.git

근데, 업데이트를 실행하고 다시 하려고하면 __init__.py 파일에서 wirte함수는 str이 아닌 unicode를 사용해야 한다는 에러를 직면할 것 이다. unicode함수를 이용하여 직접 고쳐주자.


https://github.com/Falldog/pyconcrete

 

Falldog/pyconcrete

Protect your python script, encrypt it as .pye and decrypt when import it - Falldog/pyconcrete

github.com

Comments