Home
Calendar
Certifications
Columns
Features
Forum
Resources
Vitals
Latest Additions
April 2013 Free Giveaway Sponsor - eLearnSecurity
Human Intelligence to Navigate the Security Data Deluge
February 2013 Free Giveaway Winner of SANS CyberCon Training
Interview: Bugcrowd Founders on Herding Ninjas for Crowdsourced Bug Bounties
Network Forensics: The Tree in the Forest
March 2013 Free Giveaway Sponsor - Mile2
Book Review: Violent Python
February 2013 Free Giveaway Sponsor - SANS
Holiday 2012 Free Giveaway Winner of Metasploit Pro by Rapid7
Course Review: SANS FOR408 Computer Forensic Investigations – Windows In-Depth
The Security Consulting Sugar High
Tutorial: Fun with SMB on the Command Line
Interview: Ilia Kolochenko, CEO of High-Tech Bridge
October 2012 Free Giveaway Winner of LearningGate Training
The Broken: Assessing Corporate Security in 2012 to Make a Better 2013
EH-Net Login
Welcome Guest.
Username:
Password:
Remember me
Lost Password?
No account yet?
Register
Who's Online
We have 38 guests online
You are here:
Home
Ethical Hacking Discussions and Related Certifications
Programming
First shell script... COMPLETE.
EH-Net
May 21, 2013, 05:08:46 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Go back to The Ethical Hacker Network Online Magazine
Home Page
Home
Help
Calendar
Login
Register
EH-Net
>
Ethical Hacking Discussions and Related Certifications
>
Programming
(Moderator:
don
) >
First shell script... COMPLETE.
Pages: [
1
]
2
Go Down
« previous
next »
Print
Author
Topic: First shell script... COMPLETE. (Read 5338 times)
0 Members and 1 Guest are viewing this topic.
SephStorm
Hero Member
Offline
Posts: 530
First shell script... COMPLETE.
«
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... >
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
Support my hactivities.
http://www.cafepress.com/TRUEHacker
ZeroOne
Jr. Member
Offline
Posts: 59
Re: First shell script... COMPLETE.
«
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
Logged
hayabusa
Hero Member
Offline
Posts: 1631
Re: First shell script... COMPLETE.
«
Reply #2 on:
October 01, 2012, 05:36:15 PM »
Quote from: ZeroOne 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
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
Posts: 59
Re: First shell script... COMPLETE.
«
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
Logged
hayabusa
Hero Member
Offline
Posts: 1631
Re: First shell script... COMPLETE.
«
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
Posts: 530
Re: First shell script... COMPLETE.
«
Reply #5 on:
October 01, 2012, 06:18:10 PM »
lol I was like "localhost... network
!"
but good catch on the namp.... luckily I rewrote that to post it, the orginal script spells it correctly.
Logged
Support my hactivities.
http://www.cafepress.com/TRUEHacker
hayabusa
Hero Member
Offline
Posts: 1631
Re: First shell script... COMPLETE.
«
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
Posts: 1057
aka dynamik
Re: First shell script... COMPLETE.
«
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
Posts: 669
I've just upgraded myself to a cyborg muahahaa!!1
Re: First shell script... COMPLETE.
«
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
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
Logged
I'm an InterN0T'er
SephStorm
Hero Member
Offline
Posts: 530
Re: First shell script... COMPLETE.
«
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
Support my hactivities.
http://www.cafepress.com/TRUEHacker
hayabusa
Hero Member
Offline
Posts: 1631
Re: First shell script... COMPLETE.
«
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
Posts: 669
I've just upgraded myself to a cyborg muahahaa!!1
Re: First shell script... COMPLETE.
«
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
Hence the reason I shared it hehe
Logged
I'm an InterN0T'er
SephStorm
Hero Member
Offline
Posts: 530
Re: First shell script... COMPLETE.
«
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
Support my hactivities.
http://www.cafepress.com/TRUEHacker
superkojiman
Jr. Member
Offline
Posts: 59
Re: First shell script... COMPLETE.
«
Reply #13 on:
October 01, 2012, 10:33:53 PM »
Quote from: SephStorm 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
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
Posts: 530
Re: First shell script... COMPLETE.
«
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
Support my hactivities.
http://www.cafepress.com/TRUEHacker
Pages: [
1
]
2
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
EH-Net
-----------------------------
=> Calendar Of Events
===> ChicagoCon 2007
===> ChicagoCon 2008s
===> ChicagoCon 2008f
===> ChicagoCon 2009s
=> Ethical Hacktivism
=> News Items and General Discussion About EH-Net
===> Greetings
=> Special Events
-----------------------------
Ethical Hacking Discussions and Related Certifications
-----------------------------
=> General Certification
===> Networking
===> OS
===> Security
=> Compliance, Regulations & Standards
=> Control Systems
=> Cyber Warfare
=> Forensics
===> CCE / MCCE - (Master) Certified Computer Examiner
===> CHFI - Computer Hacking Forensic Investigator
===> EnCE - EnCase® Certified Examiner
===> GCFA - GIAC Certified Forensics Analyst
=> Hardware
=> Incident Response
===> CSIH - Computer Security Incident Handler
===> GCIH - GIAC Certified Incident Handler
=> Malware
===> Advisories
=> Mobile
=> Network Pen Testing
===> CEH - Certified Ethical Hacker
===> CPTC - Certified Penetration Testing Consultant
===> CPTE - Certified Penetration Testing Engineer
===> CSTA - Certified Security Testing Associate
===> eCPPT - eLearnSecurity Certified Professional Penetration Tester
===> ECSA - EC-Council Certified Security Analyst
===> GPEN - GIAC Certified Penetration Tester
===> OSCP - Offensive Security Certified Professional
=> Physical Security
=> Programming
=> Social Engineering
=> Web Applications
=> Wireless
===> CWNP Certs
===> GAWN - GIAC Assessing Wireless Networks
===> OSWP - Offensive Security Wireless Professional
=> Other
-----------------------------
Columns
-----------------------------
=> Editor-In-Chief
=> Andress
=> Gates
=> Haddix
=> Hadnagy
=> Heffner
=> Hoffman
=> Linn
=> RichM
=> Murray
=> J. Peltier
=> Weidman
=> Wilson
-----------------------------
Features
-----------------------------
=> /root
=> Book Reviews
=> Opinions
=> Skillz
===> Examples
===> May 06 - Star Hacks, Episode V: The Empire Hacks Back
===> July 06 - Hack Bill!
===> Sept 06 - Netcat in the Hat
===> Nov 06 - Hitch-Hackers Guide to the Galaxy
===> Dec 06 - A Christmas (Hacking) Story
===> Feb 07 - Charlottes Web Site
===> April 07 - Microsoft Office Space
===> June 07 - Serenity Hack
===> Oct 07 - Worst. Ethical. Hacker. Challenge. Ever.
===> Dec 07 - Frosty the Snow Crash
===> March 2008 - It Happened One Friday
===> Oct 2008 - Scooby Doo and the Crypto Caper
===> Dec 08 - Santa Claus Is Hacking to Town
===> Feb 2009 - Brady Bunch Boondoggle
===> July 2009 - Prison Break
===> October 2009 - SSHliders
===> December 2009 - Miracle on Thirty-Hack Street
===> December 2010 - The Nightmare Before Charlie Browns Christmas
-----------------------------
Resources
-----------------------------
=> Career Central
===> Looking For Work
===> Looking To Hire
=> Links to cool sites.
=> Mass Media
=> News from the Outside World
=> Tools
=> Tutorials
===> Tutorial Requests
Loading...
Exclusive Deal
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:
Great!
Better.
About the same.
Little worse.
FUBAR!
Recent Forum Topics
GAWN - GIAC Assessing Wireless Networks
: Karen Millen Dresses Things did improve as the decade gone on
(0) by
dtree70fx
General Certification
: CPT Practical Submission
(1) by
UNIX
OSCP - Offensive Security Certified Professional
: Failed my first attempt at the OSCP exam
(94) by
azmatt
Programming
: Finished Python Course in Codecademy now what?
(11) by
securitian
Tools
: Social-Engineer Toolkit (SET) Version 5.0 “The Wild West” Released
(2) by
m0wgli
Malware
: EICAR?
(3) by
UKSecurityGuy
Advisories
: HTB23154: Multiple Vulnerabilities in Exponent CMS
(0) by
AndyP
Advisories
: HTB23153: Multiple Vulnerabilities in Jojo CMS
(0) by
AndyP
Advisories
: HTB23151: Cross-Site Request Forgery (CSRF) in UMI.CMS
(0) by
AndyP
Tutorials
: Need guidance
(8) by
r0ckm4n
OSCP - Offensive Security Certified Professional
: Class Scheduled 6/8 - Linux n00b
(7) by
Taemyks
OSCP - Offensive Security Certified Professional
: OSCP exam scheduled
(6) by
gbhat
Incident Response
: LinkedIn Forensics
(0) by
AFENTIS_Forensics
General Certification
: Red Team/Blue Team
(1) by
ajohnson
Career Central
: Starter cert?
(3) by
Grendel
Network Pen Testing
: Beginner Ethical Hacker
(1) by
m0wgli
Web Applications
: Nessus and Nikto
(4) by
Seen
Network Pen Testing
: Cracking salted MD5 hash
(4) by
n37sh@rk
CEH - Certified Ethical Hacker
: Passed my C|EH
(3) by
n37sh@rk
Mass Media
: EC-council hacked, irony at his best?
(0) by
j0rDy
Web Applications
: SQL Injection into an INSERT statement.
(6) by
eyenit0
Network Pen Testing
: Solution for sipXtapi INVITE Message CSeq Field Header Remote Overflow
(1) by
m0wgli
Web Applications
: dns
(2) by
H1t M0nk3y
Other
: BSides Boston
(0) by
3xban
Career Central
: InfoSec in Central, FL
(2) by
tturner
Web Applications
: Web vulnerability scanner
(4) by
H1t M0nk3y
EH-Net News Feeds
Latest Additions
Privacy Notice
for TDCC & All Properties
© 2013 The Ethical Hacker Network
Joomla!
is Free Software released under the GNU/GPL License.