UGR/Experiment2: Difference between revisions
From charlesreid1
No edit summary |
|||
| Line 21: | Line 21: | ||
* (optional) Python script connects to remote command-and-control server. | * (optional) Python script connects to remote command-and-control server. | ||
* (optional) stunnel trickiness | * (optional) stunnel trickiness | ||
=Implementation= | |||
==Passwordless Login Raspberry Pi== | |||
Set up passwordless login following http://charlesreid1.com/wiki/SSH#Passwordless_Login | |||
Then define the following alias in your .bashrc or wherever: | |||
<pre> | |||
alias pi="pi" | |||
function pi() { | |||
ssh-agent > ~/ssh.file # env vars in ssh.file | |||
chmod +x ~/ssh.file # execute file | |||
~/ssh.file > /dev/null | |||
rm -f ~/ssh.file | |||
export IP="10.0.0.4" | |||
ssh -Y root@${IP} # the actual ssh call | |||
} | |||
</pre> | |||
Now you can connect to the pi by typing: | |||
<pre> | |||
$ pi | |||
</pre> | |||
==Test Startup Service== | |||
Create a test startup service by doing the following. | |||
Create a custom startup script in <code>/etc/init.d/custom-script</code> with the following contents: | |||
<pre> | |||
root@kali:/etc/init.d# cat custom-script | |||
#! /bin/sh | |||
### BEGIN INIT INFO | |||
# Provides: custom-script | |||
# Required-Start: $local_fs $remote_fs | |||
# Required-Stop: $local_fs $remote_fs | |||
# Default-Start: 2 3 4 5 | |||
# Default-Stop: 0 1 6 | |||
# Short-Description: Here ya go buddy, custom script | |||
### END INIT INFO | |||
set -e | |||
touch /root/ohai | |||
exit 0 | |||
</pre> | |||
Make sure this is linked in the proper <code>rcN.d/</code> folders by running <code>update-rc.d custom-script defaults</code>. | |||
Now make sure there's no file <code>rm /root/ohai</code> and then run <code>reboot</code>. Once you reboot, you should see a file named <code>ohai</code> in the root directory. | |||
==Real Startup Service== | |||
Create a real startup service that will start capturing wifi data on boot. Assume wifi card is <code>wlan0</code>. | |||
<pre> | |||
import subprocess | |||
import time | |||
from datetime import datetime | |||
# each experiment will be Nhours in duration | |||
Nhours = 2 | |||
# each CSV file will be Nseconds in duration | |||
Nseconds = 15 | |||
# figure out how many files there will be | |||
Nfiles = (Nhours*3600)/Nseconds | |||
# create a unique file prefix for this experiment | |||
prefix = datetime.now().strftime('%Y-%m-%d_%H-%m') | |||
for i in range(Nfiles): | |||
# construct the airodump command | |||
the_cmd = ['airodump-ng','wlan0','-w',prefix,'--output-format','csv'] | |||
# call it | |||
p = subprocess.Popen(the_cmd) | |||
# wait for it | |||
time.sleep(Nseconds) | |||
# aaaaand bail | |||
p.kill() | |||
print "Success!" | |||
</pre> | |||
[[Category:Python]] | [[Category:Python]] | ||
Revision as of 05:01, 27 February 2016
Wireless Capture
Stringing together the pieces:
Here is the single-step, high level version of what we are doing. This is essentially one single step in the data pipeline.
- Sensor hardware: Raspberry Pi that can run a boot script to collect data
To get more specific:
- Be able to power on the Raspberry Pi
- Be able to remotely connect to the Raspberry Pi via SSH
- Be able to control a wireless card from the Raspberry Pi via command line
- Be able to start and stop a wireless card using Python
- Be able to start and stop airodump process using Python
Putting all the pieces together, here is how the process will look:
- Plug a wireless card into the Pi (no power)
- Plug the Pi into power
- Boot script activates Python script
- Python script identifies onboard hardware
- Python script begins running airdoump at 1 minute intervals
- (optional) Python script connects to remote command-and-control server.
- (optional) stunnel trickiness
Implementation
Passwordless Login Raspberry Pi
Set up passwordless login following http://charlesreid1.com/wiki/SSH#Passwordless_Login
Then define the following alias in your .bashrc or wherever:
alias pi="pi"
function pi() {
ssh-agent > ~/ssh.file # env vars in ssh.file
chmod +x ~/ssh.file # execute file
~/ssh.file > /dev/null
rm -f ~/ssh.file
export IP="10.0.0.4"
ssh -Y root@${IP} # the actual ssh call
}
Now you can connect to the pi by typing:
$ pi
Test Startup Service
Create a test startup service by doing the following.
Create a custom startup script in /etc/init.d/custom-script with the following contents:
root@kali:/etc/init.d# cat custom-script #! /bin/sh ### BEGIN INIT INFO # Provides: custom-script # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Here ya go buddy, custom script ### END INIT INFO set -e touch /root/ohai exit 0
Make sure this is linked in the proper rcN.d/ folders by running update-rc.d custom-script defaults.
Now make sure there's no file rm /root/ohai and then run reboot. Once you reboot, you should see a file named ohai in the root directory.
Real Startup Service
Create a real startup service that will start capturing wifi data on boot. Assume wifi card is wlan0.
import subprocess
import time
from datetime import datetime
# each experiment will be Nhours in duration
Nhours = 2
# each CSV file will be Nseconds in duration
Nseconds = 15
# figure out how many files there will be
Nfiles = (Nhours*3600)/Nseconds
# create a unique file prefix for this experiment
prefix = datetime.now().strftime('%Y-%m-%d_%H-%m')
for i in range(Nfiles):
# construct the airodump command
the_cmd = ['airodump-ng','wlan0','-w',prefix,'--output-format','csv']
# call it
p = subprocess.Popen(the_cmd)
# wait for it
time.sleep(Nseconds)
# aaaaand bail
p.kill()
print "Success!"