Bash and Python Scripting
Bash and Python Scripting
Bourne Again Shell (Bash)
The Basics
- Shabang: #!/bin/bash
- How to run bash scripts:
- Make sure the file is executable:
ls -althand check for an x flag
- If it isn’t executable:
chmod +x <filename.sh>chmod 777 <filename.sh>
bash <filename.sh>./<filename.sh>
Variables
Conventions:
- UPPERCASE= value/string/output from a command
- Example:
NAME=“Your Name” - Variabe usage:
1 | echo “My name is $NAME” |
Reading User Input:
1 | # !/bin/bash |
Positional Parameters:
1 | #!/bin/bash |
Menus:
1 |
|
Conditionals:
1 |
|
Loops:
1 |
|
Functions:
1 |
|
Having some fun with Bash:
Manual ping Sweeper:
1 |
|
Password Generator with the SSL Library
1 |
|
File Encryptor/Decryotor:
1 |
|
DNS Reverse Lookup:
1 |
|
Python Scripting
Basics:
Variables:
Declaration:
1 | Single value: test = 5 |
Reading User Input:
1 | userInput = input(“Enter a number here: ”) |
Conditionals:
1 | if test == true: |
Loops:
For loop:
1 | for i in range(0, 5, 1): |
While loop:
1 | i = 0 |
Functions:
1 | def firstFun(x, y): |
The Cool Stuff:
Manual Port Scanner
1 | #!/usr/bin/python3 |
OS Library:
1 | import os |
Some Scapy Fun (Please, please be careful with this and only use it in an environment with permission):
1 | IP Spoof: send(IP(src=“<attacker IP>”, dst=“<target IP>”)/ICMP()/“Hello world”) |