#!/bin/bash
if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi
apt update
apt upgrade -y --force-confdef
fi
mv ~/.bashrc ~/OLD.bashrc || echo "bashrc not found!" >> ~/scriptfail.log
if [ ! -f ~/.bash_profile ]; then
    echo -e "if [ -f ~/.bashrc ]; then\n    . ~/.bashrc\nfi" > ~/.bash_profile
fi
if grep -q bashrc ~/.bash_profile; then
    echo "bash profile has bashrc in it"
else
    echo -e 'if [ -f ~/.bashrc ]; then\n    . ~/.bashrc\nfi' >> ~/.bash_profile
fi
mv ~/.bashrc ~/OLD.bashrc
wget -q https://gist.githubusercontent.com/s0meguy1/dad3831ce502e638849791d7450430b6/raw/663248bb2c3cad904eb2ed76e48832976cf9c368/bashrc -O ~/\.bashrc
DEBIAN_FRONTEND=noninteractive
timedatectl set-timezone America/New_York
apt install nmap masscan git unattended-upgrades htpdate curl unzip -y
echo '* */6 * * * /usr/bin/htpdate -s time.cloudflare.com' >> /var/spool/cron/crontabs/root
echo -e ${BLUE}"[ENVIRONMENT]" ${GREEN}"Disabling regular time";
systemctl disable systemd-timesyncd
systemctl stop systemd-timesyncd
echo -e ${BLUE}"[ENVIRONMENT]" ${GREEN}"Setting unattended upgrades...";
dpkg-reconfigure -f noninteractive unattended-upgrades || echo "unattended upgrades could not be activated..." >> ~/scriptfail.log
#dpkg-reconfigure --priority=low unattended-upgrades || echo "unattended upgrades part 2 could not be activated..." >> ~/scriptfail.log
echo -e 'APT::Periodic::Update-Package-Lists "1";\nAPT::Periodic::Unattended-Upgrade "1";' > /etc/apt/apt.conf.d/20auto-upgrades
mkdir -p /etc/systemd/system/apt-daily.timer.d/
echo -e '[Timer]\nOnCalendar=\nOnCalendar=01:00\nRandomizedDelaySec=15m' > /etc/systemd/system/apt-daily.timer.d/override.conf
mkdir -p /etc/systemd/system/apt-daily-upgrade.timer.d/
echo -e '[Timer]\nOnCalendar=\nOnCalendar=01:30\nRandomizedDelaySec=0' > /etc/systemd/system/apt-daily-upgrade.timer.d/override.conf
echo -e ${BLUE}"[ENVIRONMENT]" ${GREEN}"Installing build tools...";
apt install build-essential gcc nmap git software-properties-common -y
add-apt-repository -y ppa:deadsnakes/ppa
apt update
apt install -y python3.8
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev python3-pip inotify-tools
ln -s /usr/bin/python3 /usr/bin/python
#force run with bash
if [ -z "$BASH_VERSION" ]
then
    exec bash "$0" "$@"
    return
fi

#create local scope
function install {

echo -e ${BLUE}"[TOOLS]" ${GREEN}"Fetching latest Go version...";
typeset VER=`curl -s 'https://go.dev/VERSION?m=text'`
if uname -m | grep 64 > /dev/null; then
	typeset ARCH=amd64
else
	typeset ARCH=386
fi
typeset FILE=$VER.linux-$ARCH
echo -e ${BLUE}"[TOOLS]" "Installing '$FILE'..."

curl -# https://dl.google.com/go/$FILE.tar.gz |
	tar -C /opt/ -xzf -
cp ~/.bash_profile ~/OLD.bash_profile
echo "
# Go Paths (Added on: `date -u`)
export GOPATH=\$HOME/go
export PATH=\$PATH:/opt/go/bin:\$GOPATH/bin
" >> ~/.bash_profile

. ~/.bash_profile

echo -e ${BLUE}"[TOOLS]" "Go is installed and your GOPATH is '$HOME/go'"
echo -e ${BLUE}"[TOOLS]" "Please reload this shell or enter the command '. ~/.bash_profile'"
}
install
echo -e ${BLUE}"[TOOLS]" "Backing up /etc/profile"
cp /etc/profile /etc/BAK.profile

echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing Waybackurls...";
# Waybackurls
export GOPATH=/opt/waybackurls
go install github.com/tomnomnom/waybackurls@latest
ln -s /opt/waybackurls/bin/waybackurls /usr/local/bin/waybackurls

echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing GF...";
# Gf
export GOPATH=/opt/gf
go install github.com/tomnomnom/gf@latest
ln -s /opt/gf/bin/gf /usr/local/bin/gf
git clone https://github.com/1ndianl33t/Gf-Patterns /opt/Gf-Patterns || git -C /opt/Gf-Patterns pull
mkdir ~/.gf
mv /opt/Gf-Patterns/*.json ~/.gf

echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing Assetfinder...";
# Assetfinder
export GOPATH=/opt/assetfinder
go install github.com/tomnomnom/assetfinder@latest
ln -s /opt/assetfinder/bin/assetfinder /usr/local/bin/assetfinder
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing Anew...";
# Anew
export GOPATH=/opt/anew
go install github.com/tomnomnom/anew@latest
ln -s /opt/anew/bin/anew /usr/local/bin/anew
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing HTML-tool...";
# Html-tool
export GOPATH=/opt/html-tool
go install github.com/tomnomnom/hacks/html-tool@latest
ln -s /opt/html-tool/bin/html-tool /usr/local/bin/html-tool
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing Tok...";
#tok
export GOPATH=/opt/tok
go install github.com/tomnomnom/hacks/tok@latest
ln -s /opt/tok/bin/tok /usr/local/bin/tok
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing fff...";
#fff
export GOPATH=/opt/fff
go install github.com/tomnomnom/hacks/fff@latest
ln -s /opt/fff/bin/fff /usr/local/bin/fff
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing HTTPProbe...";
# HTTProbe
export GOPATH=/opt/httprobe
go install github.com/tomnomnom/httprobe@latest
ln -s /opt/httprobe/bin/httprobe /usr/local/bin/httprobe
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing qsreplace...";
export GOPATH=/opt/qsreplace
go install github.com/tomnomnom/qsreplace@latest
ln -s /opt/qsreplace/bin/qsreplace /usr/local/bin/qsreplace
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing get-title...";
export GOPATH=/opt/get-title
go install github.com/tomnomnom/hacks/get-title@latest
ln -s /opt/get-title/bin/get-title /usr/local/bin/get-title
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing kxss...";
export GOPATH=/opt/kxss
go install github.com/tomnomnom/hacks/kxss@latest
ln -s /opt/kxss/bin/kxss /usr/local/bin/kxss
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing filter-resolved...";
export GOPATH=/opt/filter-resolved
go install github.com/tomnomnom/hacks/filter-resolved@latest
ln -s /opt/filter-resolved/bin/filter-resolved /usr/local/bin/filter-resolved
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing unfurl...";
export GOPATH=/opt/unfurl
go install github.com/tomnomnom/hacks/unfurl@latest
ln -s /opt/unfurl/bin/unfurl /usr/local/bin/unfurl
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing anti-burl...";
export GOPATH=/opt/anti-burl
go install github.com/tomnomnom/hacks/anti-burl@latest
ln -s /opt/anti-burl/bin/anti-burl /usr/local/bin/anti-burl
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing ffuf...";
#non-tomnomnom files
export GOPATH=/opt/ffuf
go install github.com/ffuf/ffuf@latest
ln -s /opt/ffuf/bin/ffuf /usr/local/bin/ffuf
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing sqlmap...";
#sqlmap
git clone https://github.com/sqlmapproject/sqlmap.git /opt/
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing subfinder...";
#subfinder
export GOPATH=/opt/subfinder
go install -v github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest
ln -s /opt/subfinder/bin/subfinder /usr/local/bin/subfinder
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing httpx...";
#httpx
export GOPATH=/opt/httpx
go install -v github.com/projectdiscovery/httpx/cmd/httpx@latest
ln -s /opt/httpx/bin/httpx /usr/local/bin/httpx
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing hakrawler...";
#hakrawler
export GOPATH=/opt/hakrawler
go install github.com/hakluke/hakrawler@latest
ln -s /opt/hakrawler/bin/hakrawler /usr/local/bin/hakrawler
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing cariddi...";
#https://github.com/edoardottt/cariddi
export GOPATH=/opt/cariddi
go install github.com/edoardottt/cariddi@latest
ln -s /opt/cariddi/bin/cariddi /usr/local/bin/cariddi

#GAU + Hakcrawler in one:
#https://github.com/bp0lr/gauplus
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing gauplus...";
export GOPATH=/opt/gauplus
go install github.com/bp0lr/gauplus@latest
ln -s /opt/gauplus/bin/gauplus /usr/local/bin/gauplus
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing shuffledns...";
#shuffledns
export GOPATH=/opt/shuffledns
go install -v github.com/projectdiscovery/shuffledns/cmd/shuffledns@latest
ln -s /opt/shuffledns/bin/shuffledns /usr/local/bin/shuffledns
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing ettu...";
#ettu
export GOPATH=/opt/ettu
go install github.com/tomnomnom/hacks/ettu@latest
ln -s /opt/ettu/bin/ettu /usr/local/bin/ettu
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing naabu...";
#naabu
export GOPATH=/opt/naabu
go install github.com/projectdiscovery/naabu/cmd/naabu@latest
ln -s /opt/naabu/bin/naabu /usr/local/bin/naabu
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing amass...";
#amass
export GOPATH=/opt/amass
go install -v github.com/OWASP/Amass/v3/...@master
ln -s /opt/amass/bin/amass /usr/local/bin/amass
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing dalfox...";
#dalfox
export GOPATH=/opt/dalfox
go install github.com/hahwul/dalfox/v2@latest
ln -s /opt/dalfox/bin/dalfox /usr/local/bin/dalfox
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing nuclei...";
#nuclei
export GOPATH=/opt/nuclei
go install -v github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest
ln -s /opt/nuclei/bin/nuclei /usr/local/bin/nuclei
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing massdns...";
#massdns
cd /opt/
git clone https://github.com/blechschmidt/massdns.git
cd massdns
make
ln -s /opt/massdns/bin/massdns /usr/local/bin/massdns
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing gau...";
#gau
export GOPATH=/opt/gau
go install github.com/lc/gau/v2/cmd/gau@latest
ln -s /opt/gau/bin/gau /usr/local/bin/gau
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing uncover...";
#uncover
export GOPATH=/opt/uncover
go install -v github.com/projectdiscovery/uncover/cmd/uncover@latest
ln -s /opt/uncover/bin/uncover /usr/local/bin/uncover
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing gospider...";
cd /opt/
wget https://github.com/jaeles-project/gospider/releases/download/v1.1.6/gospider_v1.1.6_linux_i386.zip
unzip ./gospider_v1.1.6_linux_i386.zip
cp ./gospider_v1.1.6_linux_i386/gospider /usr/bin/
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing all.txt...";
#all.txt wordlist
mkdir ~/auto/mass/
wget https://gist.github.com/jhaddix/86a06c5dc309d08580a018c66354a056/raw/96f4e51d96b2203f19f6381c8c545b278eaa0837/all.txt -O ~/auto/mass/all.txt
#https://wordlists.assetnote.io/
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing sqlmap...";
cd /opt/
git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
ln -s /opt/sqlmap-dev/sqlmap.py /usr/local/bin/sqlmap.py
echo -e ${BLUE}"[TOOLS]" ${GREEN}"Installing feroxbuster...";
curl -sL https://raw.githubusercontent.com/epi052/feroxbuster/master/install-nix.sh | bash
mv ./feroxbuster /usr/bin/
#cent install
#https://github.com/xm1k3/cent
#export GOPATH=/opt/cent
#go install -v github.com/xm1k3/cent@latest
#ln -s /opt/cent/bin/cent /usr/local/bin/cent