Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 47 guests and 2 members online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Programmingarrow First shell script... COMPLETE.
EH-Net
May 22, 2013, 04:16:03 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1] 2   Go Down
  Print  
Author Topic: First shell script... COMPLETE.  (Read 5351 times)
0 Members and 1 Guest are viewing this topic.
SephStorm
Hero Member
*****
Offline Offline

Posts: 530


View Profile WWW
« on: October 01, 2012, 04:52:41 PM »

Well I just wrote my first shell script today and I wanted to share this experience with you all. Its an amazing feeling, jr. programming 101 or something to that effect. I figured i'd share this easy script with you guys, any comments, suggestions or improvements are appreciated and desired.

I used this as my primary guide, I am still going through it, but that and some youtube videos so far gave me what I needed to build this script.

Code:
#! /bin/bash
# nmap ping scan
# used to ping a subnet

clear
namp -sP 192.168.1.0/24 > /pentest/results/scans/pingscan.txt && echo scan complete.

exit

fairly simple, but useful I hope in future studies... >Smiley  One thing I wanted to do, not sure if it's possible, but originally, I wanted "scanning..." or something to that effect to be displayed while the command was running, and then "scan complete" at the end. Can that be done without adding too much complexity?

Also, many of the examples I saw used quotation marks around statements that were to be echoed. Based on what I found, quotes are used for variables or something to that effect, can someone explain them to me, and when they should/should not be used?
« Last Edit: October 01, 2012, 04:55:38 PM by SephStorm » Logged

ZeroOne
Jr. Member
**
Offline Offline

Posts: 59


View Profile
« Reply #1 on: October 01, 2012, 05:30:22 PM »

You might wanna change "namp" to "nmap", also the gateway isn't always 192.168.1.0, the script is good over all, but try replace 192.168.1.0 with localhost so you don't have to change it every time when using different networks. Just like this:

nmap -sP localhost/24 > /pentest/results/scans/pingscan.txt && echo scan complete.

Thanks for sharing  Smiley
Logged
hayabusa
Hero Member
*****
Offline Offline

Posts: 1632



View Profile
« Reply #2 on: October 01, 2012, 05:36:15 PM »

You might wanna change "namp" to "nmap", also the gateway isn't always 192.168.1.0, the script is good over all, but try replace 192.168.1.0 with localhost so you don't have to change it every time when using different networks. Just like this:

nmap -sP localhost/24 > /pentest/results/scans/pingscan.txt && echo scan complete.

Thanks for sharing  Smiley

localhost???  Network is 0, not gateway...  He's scanning a network range.
« Last Edit: October 02, 2012, 05:53:21 AM by hayabusa » Logged

~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
ZeroOne
Jr. Member
**
Offline Offline

Posts: 59


View Profile
« Reply #3 on: October 01, 2012, 05:43:32 PM »

Ops.. forget what I said apparently blanked out & got the whole thing wrong. I need some rest. Thanks hayabusa for embarrassing me. just joking  Grin
Logged
hayabusa
Hero Member
*****
Offline Offline

Posts: 1632



View Profile
« Reply #4 on: October 01, 2012, 06:12:17 PM »

No worries.  Wasn't trying to embarrass anyone.  Just making sure we kept things straight.

Cheers, ZeroOne!
Logged

~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
SephStorm
Hero Member
*****
Offline Offline

Posts: 530


View Profile WWW
« Reply #5 on: October 01, 2012, 06:18:10 PM »

lol I was like "localhost... network Huh!"

but good catch on the namp.... luckily I rewrote that to post it, the orginal script spells it correctly.
Logged

hayabusa
Hero Member
*****
Offline Offline

Posts: 1632



View Profile
« Reply #6 on: October 01, 2012, 07:11:35 PM »

SephStorm - even before 'prettying it up' with your scanning message, might I suggest figuring out something you'll find more useful -

Work out how to pass in variables to your scripts, such that you can pass in a network address and subnet mask, from a command-line, so you could use it in other networks.  (This type of scripting will come in handy on pentests, when you can 'modularize' things and pass in variable data, for faster automation of scanning activity.)
Logged

~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
ajohnson
Recruiters
Hero Member
*
Offline Offline

Posts: 1057


aka dynamik


View Profile WWW
« Reply #7 on: October 01, 2012, 07:25:32 PM »

I also like just including one/few-liners in my .bashrc as functions or aliases
Logged

WIP: GCFA | www.infosiege.net | @infosiege

The day you stop learning is the day you start becoming obsolete.
MaXe
Hero Member
*****
Offline Offline

Posts: 669


I've just upgraded myself to a cyborg muahahaa!!1


View Profile WWW
« Reply #8 on: October 01, 2012, 08:45:24 PM »

Using arguments passed from command line is also relatively easy, you should play with this as well  Grin

Example:
echo Hi $1, you like $2 and you also like $3. The script name is $0.

Usage:
./bashscript MaXe 0days knowledge

Output:
Hi MaXe, you like 0days and you also like knowledge. The script name is bashscript.

You can also use more advanced things such as "getopts". But that example I gave you, is very handy when you need a dynamic script quickly  Smiley
Logged

I'm an InterN0T'er
SephStorm
Hero Member
*****
Offline Offline

Posts: 530


View Profile WWW
« Reply #9 on: October 01, 2012, 09:02:22 PM »

I dont think im at that level yet, i'll get right on it. *hides*
Logged

hayabusa
Hero Member
*****
Offline Offline

Posts: 1632



View Profile
« Reply #10 on: October 01, 2012, 09:06:06 PM »

Nah.  I got confidence in you.  MaXe literally gave you all you need, in order to do it.  It really IS that easy!
Logged

~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
MaXe
Hero Member
*****
Offline Offline

Posts: 669


I've just upgraded myself to a cyborg muahahaa!!1


View Profile WWW
« Reply #11 on: October 01, 2012, 09:37:46 PM »

I was surprised when I found out there was a way easier option than getopts  Grin Hence the reason I shared it hehe  Smiley
Logged

I'm an InterN0T'er
SephStorm
Hero Member
*****
Offline Offline

Posts: 530


View Profile WWW
« Reply #12 on: October 01, 2012, 09:48:53 PM »

If i'm not mistaken, you are talking about variables here right?

like this?

http://tldp.org/LDP/abs/html/varsubn.html
Logged

superkojiman
Jr. Member
**
Offline Offline

Posts: 60



View Profile WWW
« Reply #13 on: October 01, 2012, 10:33:53 PM »

If i'm not mistaken, you are talking about variables here right?

like this?

http://tldp.org/LDP/abs/html/varsubn.html

Yes. Arguments passed into the program are assigned to $1, $2, $3, $4, and so on, with $0 being the name of the program itself. It's actually not that complicated, bash is a pretty easy thing to learn. If you check the manual for bash, you'll see a lot of neat tricks and things you can incorporate into your script.
Logged

OSCP, GSEC
SephStorm
Hero Member
*****
Offline Offline

Posts: 530


View Profile WWW
« Reply #14 on: October 01, 2012, 10:56:40 PM »

I think I know what MaXe is saying here, instead of the arguments being defined explicitly in the script, I can specify them in my command string and have for instance:

Code:
#! /bin/bash
# nmap ping scan
# used to ping a subnet

clear
nmap -sP $IP > /pentest/results/scans/$scanname.txt && echo scan complete.

exit

./pingscan.sh 192.168.1.0/24 pingscan

correct?
Logged

Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.061 seconds with 23 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.