Scripting

TODO: Separate Bash and Python scripting pages...and add more

Bash

Bash Scripting Basics

[+] Shebang:

#!/bin/bash

[+] Variables

name=Bob
echo $name
user=$(whoami)
echo $user
echo 'Hello' $name. 'You are running as' $user.

[+] Simple script example

#!/bin/bash
clear
echo "Hello World"
name=Bob
ip=`ifconfig | grep "Bcast:" | cut -d":" -f2 | cut -d" " -f1`
echo "Hello" $name "Your IP address is:" $ip

[+] User Input

Example script with read

[+] Check For No User Input

[+] For loops

[+] Port Scan one liner

Check for root privileges

When user account created a user ID is assigned to each user. BASH shell stores the user ID in the $UID environment variable. The effective user ID is stored in the $EUID variable.

You can easily add a simple check at the start of a script to make sure it is being run with root privileges.

Old way to check for root privileges

New way: Using EUID

MISC

https://www.techbrown.com/most-useful-bash-scripts-linux-sysadmin/

Add to multitool.sh:create wordlists with cewl & Hashcat; add add options to use mangling rules;

Add to multitool.sh: crack passwords with Hashcat

Python

Python Functions

Dealing with Sockets

https://pequalsnp-team.github.io/cheatsheet/socket-basics-py-js-rb

MISC

PHP

PHP Functions

PHP Server

https://www.php.net/manual/en/features.commandline.webserver.php When starting php -S on a mac (in my case macOS Sierra) to host a local server, I had trouble with connecting from legacy Java. As it turned out, if you started the php server with php -S localhost:80 the server will be started with ipv6 support only! To access it via ipv4, you need to change the start up command like so: php -S 127.0.0.1:80 which starts server in ipv4 mode only.

It’s not mentioned directly, and may not be obvious, but you can also use this to create a virtual host. This, of course, requires the help of your hosts file. Here are the steps:

In order to set project specific configuration options, simply add a php.ini file to your project, and then run the built-in server with this flag: php -S localhost:8000 -c php.ini

Example #6 Accessing the CLI Web Server From Remote Machines You can make the web server accessible on port 8000 to any interface with: $ php -S 0.0.0.0:8000

Example #2 Starting with a specific document root directory

PHP Jail Escape

With file_get_contents()

With readfile()

With popen()

With highlight_file()

With highlight_source()

With Finfo()

If you like this content and would like to see more, please consider buying me a coffee!

Last updated