You are not logged in.

#1 2015-07-31 08:49:27

Masstumor
Member
Registered: 2015-05-19
Posts: 14

[Solved] Script Warning Program 'bash' crashed.

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

#2 2015-07-31 09:47:02

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: [Solved] Script Warning Program 'bash' crashed.

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)


pkgshackscfgblag

Offline

#3 2015-07-31 09:56:09

Masstumor
Member
Registered: 2015-05-19
Posts: 14

Re: [Solved] Script Warning Program 'bash' crashed.

Thank you, That's what I was looking for.

Offline

#4 2015-07-31 10:04:39

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [Solved] Script Warning Program 'bash' crashed.

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

#5 2015-07-31 10:14:32

Masstumor
Member
Registered: 2015-05-19
Posts: 14

Re: [Solved] Script Warning Program 'bash' crashed.

Raynman wrote:

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

Board footer

Powered by FluxBB