You are not logged in.
I'm working on my first bash script to speed up setting up my fake router, it does everything I want the only issue I have is in ending the script. When I am done messing with the fake router I end it with CTRL + C. Doing this results in this:
04:48:54 Created tap interface at0
04:48:54 Trying to set MTU on at0 to 1500
04:48:54 Access Point with BSSID 1A:15:6E:A2:AC:57 started.
^C
Warning: Program 'bash' crashed.
This is what I have so far, pretty basic. Puts wlan0 down, swaps the mac, places wlan0 in monitor mode, tests packet injection then starts the fake router.
#!/bin/bash
[[ `id -u` -eq 0 ]] || { echo "Must be root to run script"; exit 1; }
tput setaf 2;
echo "Taking down wlan0..."
tput setaf 6;
echo "ifconfig wlan0 down"
ifconfig wlan0 down
sleep 3
tput setaf 2;
echo "Changing mac"
tput setaf 6;
macchanger -r wlan0
tput setaf 2;
echo "Placing wlan0 into monitor mode..."
echo "iwconfig wlan0 mode monitor"
tput setaf 6;
iwconfig wlan0 mode monitor
sleep 3
tput setaf 2;
echo "Testing to see if packet injection works..."
echo "aireplay-ng -9 wlan0"
tput setaf 6;
aireplay-ng -9 wlan0
sleep 3
tput setaf 2;
echo "Starting our fake router..."
echo "airbase-ng -c 11 -e Hotspot wlan0"
tput setaf 6;
airbase-ng -c 11 -e Hotspot wlan0
Could someone point me in the right direction for properly ending a bash script with user commands. Not really looking for just a answer.
Last edited by Masstumor (2015-07-31 09:56:39)
Offline
Hi
There is the `trap` command. It has the form
trap <function> <signal>
which will execute <function> if the process receives the signal <signal>.
Besides, commands like `ifconfig` and `iwconfig` are deprecated in favour of `ip`/`iw`.
For instance you'd have
ip link set dev wlan0 down
macchanger -r wlan0 # or also (but that's not random): ip link set dev wlan0 address AA:BB:CC:DD:EE:FF
iw dev wlan0 set type monitor
...
EDIT
To elaborate a little on the `trap` command - I'd perhaps run the last command (the one that blocks, `airbase-ng`) in background, get its PID, then wait. Once you get a SIGINT/SIGTERM signal, you kill the PID, then do some cleanup:
interrupt()
{
kill $airbase_pid
}
...
trap interrupt SIGINT SIGTERM # set signal handler
airbase-ng -c 11 -e Hotspot wlan0 & # run in background
airbase_pid=$! # get PID for later
wait $airbase_pid # block
iw dev wlan0 set type managed # cleanup
Last edited by ayekat (2015-07-31 10:05:32)
{,META,RE}PKGBUILDS │ pacman-hacks (includes makemetapkg and remakepkg) │ dotfileslocaldir
Offline
Thank you, That's what I was looking for.
Offline
Some googling suggests messages like this one are a Konsole (KDE terminal emulator) thing. Using Ctrl-C shouldn't be a problem, but the exit status indicates that the script exited in response to this signal and it seems Konsole interprets this as a crash.
Somewhat related: https://bugs.kde.org/show_bug.cgi?id=168539
If there is indeed no real crash, you can ignore it, use a different terminal emulator or try to cover up the real reason for exiting using a trap handler.
Also related: http://www.cons.org/cracauer/sigint.html
Last edited by Raynman (2015-07-31 10:08:18)
Offline
Some googling suggests messages like this one are a Konsole (KDE terminal emulator) thing. Using Ctrl-C shouldn't be a problem, but the exit status indicates that the script exited in response to this signal and it seems Konsole interprets this as a crash.
Somewhat related: https://bugs.kde.org/show_bug.cgi?id=168539
If there is indeed no real crash, you can ignore it, use a different terminal emulator or try to cover up the real reason for exiting using a trap handler.
Also related: http://www.cons.org/cracauer/sigint.html
I seen those as well while searching, I haven't tried in another terminal yet. Mainly was looking for a way to properly end the script. Maybe build on them more as I learn. The trap method mentioned above is exactly what I was looking for. But I will test on another terminal here soon. Thanks for the replies.
Offline