Author: seana11
Subject: CTF Securing Utility (Linux)
Posted: 14 Oct 2012 02:44:48 am (GMT -5)
I played a game CTF with computers yesterday, and was irked by the amount of time doing stuff manually. I created this script to help automate some of the tasks that need to be performed. It is written in bash and currently does around 5 tasks. It was created for backtrack linux, but should work on other distros.
Code:
_________________
![]()
Code:
decoded
Subject: CTF Securing Utility (Linux)
Posted: 14 Oct 2012 02:44:48 am (GMT -5)
I played a game CTF with computers yesterday, and was irked by the amount of time doing stuff manually. I created this script to help automate some of the tasks that need to be performed. It is written in bash and currently does around 5 tasks. It was created for backtrack linux, but should work on other distros.
Code:
#!/bin/bash
#Flag Runner
#v0.0.2
#
#Secures a backtrack box
#Current tasks:
#Changes root password, prints all users, runs nmap on localhost, configures iptables, and randomizes the MAC address
#VARIABLES
iptablerules="/etc/iptables.rules"
iptableload="/etc/network/if-pre-up.d/ifconfigload"
iptablesave="/etc/network/if-post-down.d/ifconfigsave"
#FUNCTIONS
#Displays the "press any key" prompt
pause () {
echo "Press any key to continue..."
read -rs -n 1
}
#Displays the argument in bold
bold () {
tput bold
echo $1
tput sgr0
}
#Change the root password
bold "Changing root password:"
#passwd
#List all users with UIDs >=1000
echo "Printing all users with UID greater than 1000:"
#Set the field delimeter to : and read in all the fields
while IFS=: read -r f1 f2 f3 f4 f5 f6 f7; do
#Test if they are over 1000
if test $f3 -ge 1000; then
echo "There is a user $f1 ($f5) with the home directory of $f6 and the default shell of $f7"
fi
done < /etc/passwd
pause
#Do nmap before setting up our firewall so we can check what ports are open by default
bold "Running nmap..."
nmap -sS -sU -p 1-65535 -v -T5 localhost
pause
#Configure iptables
echo "Configuring iptables..."
#Clear everything out first
iptables --flush
#Never forward packets
iptables -P FORWARD DROP
#Allow everything on loopback
iptables -I INPUT 1 -i lo -j ACCEPT
#Allow packets that are part of an existing connection
iptables -I INPUT 2 -m state --state RELATED,ESTABLISHED -j ACCEPT
#Allow reverse payloads for metasploit
iptables -I INPUT 3 -i eth0 -p tcp --dport 443 -m state --state NEW -j ACCEPT
#Drop everything else
iptables -A INPUT -j DROP
#Print current iptables config
bold "Current iptables config:"
iptables -L
pause
#Create a script to load the config to on startup
echo "Creating iptables startup script..."
echo -e "#\!/bin/bash\niptables-restore < $iptablerules\nexit 0" > $iptableload
chmod +x $iptableload
#Create a script to load the config on shutdown
echo "Creating iptables shutdown script..."
echo -e "#\!/bin/bash\niptables-save -c > $iptablerules\nexit 0" > $iptablesave
chmod +x $iptablesave
#Randomize MAC Address
tput bold;read -n 1 -p "Randomize MAC Address? (y/N)" input;tput sgr0
if [[ $input == "y" ]]; then
bold "Randomizing MAC Address..."
ip link set eth1 down
macchanger -A eth1
ip link set eth1 up
fi
_________________


Code:
-----BEGIN GEEK CODE BLOCK-----
GCS d- s+: a---@ C+++ UL++ P L+++ E- W++ N o? K? w--- O? M--
V- PS++(--) PE- Y+ PGP t 5? X(+) R tv-- b++(+++) DI+(++)
D(+) G e-(*)>++@ h! r!>+++ y?
------END GEEK CODE BLOCK------