<commit_before>Marty's guide to running a picoCTF server with vagrant, virtualbox and Ubuntu
NOTE: pay attention to eno3 below in /etc/iptables/rules.v4 -- it may be different (check with ip a)

Install Ubuntu LTS (18.04)

sudo apt-get install virtualbox
wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb
sudo dpkg -i ./vagrant_2.2.7_x86_64.deb
git clone https://github.com/picoCTF/picoCTF.git
mv picoCTF picoCTF_csce465_s20
cd picoCTF_csce465_s20
J=4 M=8 WIP=192.168.2.52 SIP=192.168.2.53 vagrant up --provision shell && J=2 M=8 WIP=192.168.2.52 SIP=192.168.2.53 vagrant up --provision web


sudo apt-get install apache2
sudo a2enmod proxy proxy_http

sudo vi /etc/apache2/sites-available/reverse-proxy.conf

# Use two hostnames that you can set DNS entries to point
# to the Ubuntu server, one for the web and one for the shell
# in the example below, hulkcybr1 is the front end and
# csce465shell is the shell
<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName hulkcybr1.dhl.tamu.edu
    ProxyPass / http://192.168.2.52/
    ProxyPassReverse / http://192.168.2.52/
</VirtualHost>

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName csce465shell.martincarlisle.com
    ProxyPass / http://192.168.2.53/
    ProxyPassReverse / http://192.168.2.53/
</VirtualHost>

sudo service apache2 restart

sudo apt-get install iptables-persistent

sudo vi /etc/iptables/rules.v4

# Generated by iptables-save v1.6.1 on Thu Mar 19 18:10:15 2020
*nat
:PREROUTING ACCEPT [45:6427]
:INPUT ACCEPT [3:218]
:OUTPUT ACCEPT [4:240]
:POSTROUTING ACCEPT [4:240]
-A PREROUTING -i eno3 -p tcp -m tcp --dport 8022 -m state --state NEW,RELATED,ESTABLISHED -j DNAT --to-destination 192.168.2.53:22
-A POSTROUTING -o vboxnet0 -j MASQUERADE
COMMIT
# Completed on Thu Mar 19 18:10:15 2020
# Generated by iptables-save v1.6.1 on Thu Mar 19 18:10:15 2020
*filter
:INPUT ACCEPT [249198:359039279]
:FORWARD ACCEPT [23:3733]
:OUTPUT ACCEPT [96631:5471893]
COMMIT
# Completed on Thu Mar 19 18:10:15 2020

sudo iptables-restore < /etc/iptables/rules.v4

## Note when you are generating web problems, you'll want to use the
## DNS name from above for the shell, and the /problems/port/ interface
## (e.g.)

{
  "name": "SQL Injection",
  "category": "Web Exploitation",
  "pkg_dependencies": ["php-sqlite3"],
  "description": "There is a website running at <code>http://csce465shell.martincarlisle.com/problem/{{port}}/</code> (<a href=\"http://csce465shell.martincarlisle.com/problem/{{port}}/\">link</a>). Try to see if you can login!",
  "score" : 8,
  "hints": ["When you click on the source code link, right click and view source"],
  "author": "<NAME>",
  "organization": "Carnegie Mellon",
  "event" : "CSCE465"
}
<commit_msg>add uwsgi fix for /problem<commit_after>Marty's guide to running a picoCTF server with vagrant, virtualbox and Ubuntu
NOTE: pay attention to eno3 below in /etc/iptables/rules.v4 -- it may be different (check with ip a)

Install Ubuntu LTS (18.04)

sudo apt-get install virtualbox
wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb
sudo dpkg -i ./vagrant_2.2.7_x86_64.deb
git clone https://github.com/picoCTF/picoCTF.git
mv picoCTF picoCTF_csce465_s20
cd picoCTF_csce465_s20
J=4 M=8 WIP=192.168.2.52 SIP=192.168.2.53 vagrant up --provision shell && J=2 M=8 WIP=192.168.2.52 SIP=192.168.2.53 vagrant up --provision web


sudo apt-get install apache2
sudo a2enmod proxy proxy_http

sudo vi /etc/apache2/sites-available/reverse-proxy.conf

# Use two hostnames that you can set DNS entries to point
# to the Ubuntu server, one for the web and one for the shell
# in the example below, hulkcybr1 is the front end and
# csce465shell is the shell
<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName hulkcybr1.dhl.tamu.edu
    ProxyPass / http://192.168.2.52/
    ProxyPassReverse / http://192.168.2.52/
</VirtualHost>

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName csce465shell.martincarlisle.com
    ProxyPass / http://192.168.2.53/
    ProxyPassReverse / http://192.168.2.53/
</VirtualHost>

sudo service apache2 restart

sudo apt-get install iptables-persistent

sudo vi /etc/iptables/rules.v4

# Generated by iptables-save v1.6.1 on Thu Mar 19 18:10:15 2020
*nat
:PREROUTING ACCEPT [45:6427]
:INPUT ACCEPT [3:218]
:OUTPUT ACCEPT [4:240]
:POSTROUTING ACCEPT [4:240]
-A PREROUTING -i eno3 -p tcp -m tcp --dport 8022 -m state --state NEW,RELATED,ESTABLISHED -j DNAT --to-destination 192.168.2.53:22
-A POSTROUTING -o vboxnet0 -j MASQUERADE
COMMIT
# Completed on Thu Mar 19 18:10:15 2020
# Generated by iptables-save v1.6.1 on Thu Mar 19 18:10:15 2020
*filter
:INPUT ACCEPT [249198:359039279]
:FORWARD ACCEPT [23:3733]
:OUTPUT ACCEPT [96631:5471893]
COMMIT
# Completed on Thu Mar 19 18:10:15 2020

sudo iptables-restore < /etc/iptables/rules.v4

## Note when you are generating web problems, you'll want to use the
## DNS name from above for the shell, and the /problems/port/ interface
## (e.g.)

{
  "name": "SQL Injection",
  "category": "Web Exploitation",
  "pkg_dependencies": ["php-sqlite3"],
  "description": "There is a website running at <code>http://csce465shell.martincarlisle.com/problem/{{port}}/</code> (<a href=\"http://csce465shell.martincarlisle.com/problem/{{port}}/\">link</a>). Try to see if you can login!",
  "score" : 8,
  "hints": ["When you click on the source code link, right click and view source"],
  "author": "<NAME>",
  "organization": "Carnegie Mellon",
  "event" : "CSCE465"
}

Also, you'll need to modify the nginx.conf on the shell server to 
replace 192.168.2.53 (or whatever) with the hostname being used (e.g. csce465shell.martincarlisle.com)
{'fraction_non_alphanumeric': 0.12188218644967275, 'fraction_numerical': 0.094109322483637, 'mean_word_length': 4.021314387211367, 'pattern_counts': {'":': 14, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 19, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4975721', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2110, 'n_words': 639}