Showing posts with label Penetration Testing. Show all posts
Showing posts with label Penetration Testing. Show all posts

How to Perform Remote Tunneling

Hello friends! Previously we had discussed on Dynamic tunneling and Local tunneling and today we are going to discuss Remote tunneling.

Remote tunneling is functional when a client machine wants to access a remote system which is outward from its network.

Example: Your personal laptop (at home) is connected with your office server; currently you are working on a client system (at office) which is connected to office server. Now if you want to connect your client system with laptop in order to read some document then there should be a remote tunnel between them for communication.

Let’s Begin!!
Objective:  To establish HTTP connection between remote PC and client server of different network.
Here I have set my own lab which consist three systems in following network:
SSH server (two Ethernet interface) 
IP 192.168.0.116 connected to remote system 192.168.0.100
IP 192.168.10.1 connected to local network system 192.168.10.2
Ubuntu client (local network system) holds IP 192.168.10.2
Remote system (outside network) holds IP 192.168.0.100


Given image below is describing the network configuration for SSH server where it is showing two IP 192.168.0.116 and another 192.168.10.1 as explain above.


Another image given below is describing network configuration for ubuntu client which is showing IP 192.168.10.2


Another image given below is describing network configuration for Remote Desktop whose IP is 192.168.0.100


Since in this tutorial we are showing HTTP tunneling and this service is running on port 80 of Xampp server (at localhost).
From given image you can observe that the wordpress website is running on port 80.


At SSH server we have successfully browse wordpress website using URL http://192.168.0.100/index.html and get connected with remote desktop, since they belongs to same network hence they both can access each other network for communication.

Similarly we had tried connect remote Desktop with ubuntu client through URL http://192.168.0.100/index.html but get failed to browse wordpress website. Since they both belong to different network hence connection forbidden here.


Now try to establish link between remote desktop and ubuntu client using putty.
Use putty to connect SSH server (192.168.0.116) via port 22 and follow given below steps.


Then go with option SSH >Tunnel specified in the left column of category and follow given below steps:
1.       Mark the check box for “Local ports accept connections from other hosts
2.       Give new port forwarded as 7000 and connection type as remote.
3.       Destination address as 127.0.0.1:80 for establishing connection and then click on ADD at last
4.       Click on open when all things are set.


Note: If SSH service is activated at remote desktop then replaces port 80 with port 22 which will create Remote SSH tunneling.


This will first establish the connection between remote pc and SSH server which will act like a link between remote desktop and ubuntu client throughout communication.


Now open the browser inside ubuntu client and again try to connect with remote desktop using URL http://192.168.0.116:7000/index.html this will browse wordpress website which was running on localhost of remote desktop via SSH server on port 7000.
Hence we had successfully connected with remote desktop through ubuntu client.

Setup DNS Penetration testing Lab in Windows Server 2012

Domain Name System is used for name translation into IP address or you can say that it is used for name resolution.
This name is only for the benefit of the human. It is translated into IP addresses to reach the destination. The translation process of a name is called name resolution.
Name resolution starts from right to left. There is another "." after com but it is hidden. This is called root level domain. Winner request is sent to the root domain for translation it forwards this request to com domain which is called Top Level Domain. Com passes the request to yahoo domain which is called 2ndlevel domain .Yahoo then sends the request to www which is called host name.
Structure of the DNS is distributed over the internet. It means that the name resolution task is not assigned to only computer rather it is distributed over the internet.

Steps to Install DNS server

Configure Static IP setting of your server; here we had assigned 192.168.1.104 IP to our machine moreover we had assign server IP also as preferred DNS server.



We have to open Server Manager and then click on Add Roles and Features in order to install role services and features. A new window will come up on screen. Now click on next as shown below in given image.


Select installation type “role based or feature based installation” which is also select as default option and then click on next for further step.


Select the desire server from server pool for configuration of DNS server. From given below image you can observe that  from inside pool 1 computer is found with IP 192.168.1.104 that has been selected as server, now click on next.


Select DNS server checkbox as role to install it on selected server and click on Next.


Now Just Click on Next after reading brief description of DNS.


To install selected role and feature on selected server click on install.


DNS server installation process begins which may takes few minute for installation, at last click on close once the installation has been completed.


This is all about DNS installation now in next step we will configure DNS server.

Zone
Database of DNS is called zone or partition of Domain Name Space represented by Domain Name is called Zone. When you click on zone then you will see two zones one is Forward Lookup Zone and Reverse Lookup Zone.
Forward Lookup Zone sends name and get IP address of the computer.
While Reverse Lookup Zone sends IP address of the computer then why we need name of the computer. The answer is that if firewall is installed on the computer then firewall stop or allow traffic on the basis of name that is why reverse lookup zone is used to convert IP address in the name.
Steps to create a Forward Lookup zone:
1)      Select DNS from drop down list server manger, this will open the server on which we have install DNS role.  Select your server (WIN-KSR8OM147HH ) make right click on it  and select DNS from that list.


When we select DNS in server Manager it will open a new window as DNS Manager.
Now we will configure Forward lookup zone as well as Reverse Lookup Zone. So to create Forward Lookup Zone, select Forward Lookup Zones and right click on it and select New Zone from menu box to take up the New Zone Wizard then click on next.

It will show the list of Different types of Zones and storage such as Primary Zone, Secondary Zone & Stub Zone.


Zone Types

Primary Zone:  A primary DNS zone has authority of read / writes for DNS server also known as master server. It stores the master copy of zone data in a local file or in AD DS

Secondary Zone:  A Secondary DNS Zone is Read-Only copy of a Primary Zone; this DNS server is a secondary resource for information about this zone.

Active Directory Integrated DNS Zone: It is also writeable zone. To make Active Directory Integrated zone the machine must be a domain Controller. RODC (read only domain controller).feature is only available in server 2008 R2.The domain controller must be writeable not read only because it is more secure. There is a security tab in the AD integrated zone, it is a multi master structured. In case of AD integrated zone, DNS database will be replicated as a part of domain replication.

Stub zone: It is nature secondary. It has no database of its own. Its load the database from master DNS. It only takes selective records not the complete database. Three records NS, SOA and Glue A will transfer into stub zone. Stub is read only.

DNS uses port 53 for communication and it uses both TCP and UDP protocols. Dynamic DNS (DDNS) is used to automatically update IP addresses in DNS when changed by DHCP. You will enable DDNS option in the zone properties to secure only.


Select primary zone and click on next.


Give desired Zone name like raj and click on next.


Save this into a new zone file as raj.dns and click on next.

Select Do not allow dynamic updates option, if you want to update these records manually .Click on next then Finish.


Now we had completed the configuration for Forward Lookup Zone; next we will configure reverse lookup zone.
Reverse Lookup Zone:
Domain Name system (DNS) servers can enable clients to determine the DNS name of a host based on the host's IP address by providing a special zone called a reverse lookup zone. A reverse lookup zone contains pointer (PTR) resource records that map IP addresses to the host name. Some applications, such as secure web applications, rely on reverse lookups.
A reverse lookup takes the form of a question, such as "can you tell me the DNS name of the computer that uses the IP address 192.168.1.120?"
A special domain, the in-addr.arpa  domain, was defined in the DNS standards and reserved in the internet DNS namespace to provide a practical and reliable way to perform reverse queries . In reverse lookup zone the address is written in reverse order.
Step to create a Reverse Lookup Zone:
To create Reverse Lookup Zone, make right click on it and click on New Zone from the inside the menu box to take up the New Zone Wizard.


Select primary zone and click on next.


Click on first radio button for IPv4 reverse Lookup Zone to translate IP address into DNS name then click on next.


Type Network ID field as 192.168.1 which is the first three octets of IP-address of our DNS Server then click on next.


Save this in a new zone file and select first radio button for this step then click on next.


Select Do not allow dynamic updates option, if you want to update these record manually. Click on next.


We have successfully completed configuration for new zone of reverse Lookup. Now just click on finish.


Now you can observe that on the right side of DNS Manager Window, Reverse Lookup Zone is now created that contains two records i.e. SOA and NS in it.

1)      Now we are going to create a new pointer in our new zone file i.e. 1.168.192.in-addr.arpa, as shown in given below image


Here we require host name in order to create new resource record, click on browse to select the record.
Resource Records
Resource records are the DNS database entries to answer DNS client queries. Name, type and data. The client query is always shown under the name title; DNS server answer always shown under the data title, in type different types of records is shown. Common recorded in DNS are A (Name to IP), PTR (reverse of A), SRV, MX, MS, SOA, etc.


Select 2ndfile i.e. name server (NS) record as shown in given below image and click on OK.


DNS Queries
There are two types of queries in DNS:
·         Recursive Query: - It goes from DNS client to DNS server. It answer is complete means processing is complete.
·         Iterative Query: - It goes from DNS server to DNS server. It answer is not complete means its reply is referral. Iterative query is used to reach from one DNS to another DNS. It keeps the reply for 60minutes in his cache.


Verify DNS configuration
Open command prompt and type following command which will search for the Domain Name System (DNS) to find domain name or IP address mapping.
Nslookup 192.168.1.104 (server’s ip)
From given below image you can read the name of NS record/domain name i.e. raj.

Similarly using command nslookup raj we found host IP i.e. 192.168.1.104


How to Secure Port using Port Knocking

Port knocking is a technique use for sending of information through closed ports on a connected computer in a network behind a firewall. It will add security in your network for establishing connection with a particular port until the correct sequence of port is not knocked. The network administer configure port knocking using iptable which act like firewall.
Iptable chain allows a client who is familiar with the secret knock to enter the network through a specific port by performing a sequence of connection attempts. 

The main reason of port knocking is to avoid an attacker from scanning a system for potentially vulnerable services by performing a port scan, because if the attacker will not sends the accurate knock sequence, the protected ports will appear closed.

Port knocking with Iptables

Iptables is a command-line firewall service in Linux kernel that uses rule chains to permit or obstruct traffic. It defined various tables that contain a number of integrated chains which may be containing user-defined chains also. Iptable chain is a list of policy that is used to match a set of packets. Every rule/policy specifies the function that should be done with packets that matches

Type given below command with the help of following option which will create a new iptable chain:

-F: --flush [chain]
Flush the selected chain (all the chains in the table if none is given). This is equivalent to deleting all the rules one by one.
-X: delete-chain [chain]
Delete the optional user-defined chain specified. There must be no references to the chain. If there are, you must delete or replace the referring rules before the chain can be deleted. The chain must be empty, i.e. not contain any rules. If no argument is given, it will attempt to delete every non-builtin chain in the table.
-Z: --zero [chain [rulenum]]
Zero the packet and byte counters in all chains, or only the given chain, or only the given rule in a chain. It is legal to specify the -L, --list (list) option as well, to see the counters immediately before they are cleared. 
-N: --new-chain chain
Create a new user-defined chain by the given name. There must be no target of that name already.
-A: --append chain rule-specification
Append one or more rules to the end of the selected chain. When the source and/or destination names resolve to more than one address, a rule will be added for each possible address combination.
-p: --protocol protocol
The protocol of the rule or the packet to check. The specified protocol can be one of tcp, udp, udplite, icmp, esp, ah, sctp or the special keyword "all", or it can be a numeric value, representing one of these protocols or a different one. A protocol name from /etc/protocols is also allowed. A "!" argument before the protocol inverts the test. The number zero is equivalent to all. All will match with all protocols and is taken as default when this option is omitted.
-m: --match match
Specifies a match to use, that is, an extension module that tests for a specific property. The set of matches make up the condition under which a target is invoked. Matches are evaluated first to last as specified on the command line and work in short-circuit fashion, i.e. if one extension yields false, evaluation will stop.
-j: --jump target
This specifies the target of the rule; i.e., what to do if the packet matches it. The target can be a user-defined chain (other than the one this rule is in), one of the special built-in targets which decide the fate of the packet immediately, or an extension. For example ACCEPT DROP and REJECT.

From ipset.netfilter.org

Iptables -F
Iptables -X
Iptables -Z
Iptables -N STATE0
Iptables -A STATE0 -p tcp -dport 1200 -m recent -name KNOCK1 -set -j DROP
Iptables -A STATE0 -j DROP
Iptables -N STATE1
Iptables -A STATE1 -m recent -name KNOCK1 -remove
Iptables -A STATE1 -p tcp -dport 1300 -m recent -name KNOCK2 -set -j DROP
Iptables -A STATE1 -j STATE0
Iptables -N STATE2
Iptables -A STATE2 -m recent -name KNOCK2 -remove
Iptables -A STATE2 -p tcp -dport 1400 -m recent -name KNOCK3 -set -j DROP
Iptables -A STATE2 -j STATE0
Iptables -N STATE3
Iptables -A STATE3 -m recent -name KNOCK3 -remove
Iptables -A STATE3 -p tcp -dport 22 -j ACCEPT
Iptables -A STATE3 -j STATE0
Iptables -A INPUT -m state - state ESTABLISHED,RELATED -j ACCEPT
Iptables -A INPUT -s 127.0.0.1/8 -j ACCEPT
Iptables -A INPUT -p icmp -j ACCEPT
Iptables -A INPUT -p tcp -dport 80 -j ACCEPT
Iptables -A INPUT -m recent -name KNOCK3 -rcheck -j STATE3
Iptables -A INPUT -m recent -name KNOCK2 -rcheck -j STATE2
Iptables -A INPUT -m recent -name KNOCK1 -rcheck -j STATE1
Iptables -A INPUT -j STATE0


Let’s verify it through port scanning using NMAP command.
Nmap -ST 192.168.0.25
From given below image you can observe that NMAP found only PORT 80 is open.


Type apt-get install knockd command to install knockd.
Knockd is a port-knock command-line utility. It snoops to all traffic on an Ethernet interface, come across for particular "knock" sequences of port knocks. A client makes these port-hits through sending a TCP or UDP packet to a port on the server.


Now type following command for port knocking
Knock -v 192.168.0.25 1200 1300 1400
From given image you can observe that it will start hitting on a particular port which is actually known as port knocking. Since client is aware of sequence he can make correct knocked sequence for connection attempts.


Again use port scanning with NMAP on same target
Nmap -p 192.168.0.25
Hence you can see the difference between both NMAP’s result as this time we got port 22 open for SSH service.


Now client will use credential for login into SSH server.
Conclusion! Network admin adds the filter with specific port that will wait for correct knock sequence which will then open the port to establish the connection otherwise it will remain closed the port until correct port knocked

How to Perform Local SSH Tunneling

Hello Friends! Previously we have discussed on SSH tunnel and step to perform dynamic tunneling (port forwarding) which you can read from here. Today we will talk on same scenario and perform local tunneling (port forwarding).
Local tunneling is a process to access a specific SSH client machine for communication. It let you establish the connection on a specific machine which is not connected from internet.
The only difference between dynamic tunneling and local tunneling is that, dynamic tunneling requires socks proxy for tunneling all TCP traffic and local tunneling only required destination IP address.
Let’s Begin!!
Objective:  To establish SSH connection between remote PC and local system of different network.
Here I have set my own lab which consist three systems in following network:
1.      SSH server (two Ethernet interface) 
                 i.   IP 192.168.1.217 connected to remote system 192.168.1.219
               ii.   IP 192.168.10.2 connected to local network system 192.168.10.2
2.      SSH client (local network) holds IP 192.168.10.2
3.      Remote system (outside network) holds IP 192.168.1.219


Given image below is describing the network configuration for SSH server where it is showing two IP 192.168.1.217 and another 192.168.10.1 as explain above.


Another image given below is describing network configuration for SSH client which is showing IP 192.168.10.2


Remote Pc (192.168.1.219) is trying to connect to SSH server (192.168.1.217) via port 22 and get successful login inside server.


Similarly now Remote PC (192.168.1.219) trying to connect with Client PC (192.168.10.2) via port 22, since they belongs to different network therefore he receive network error.


Step for SSH Local tunneling
·         Use putty to connect SSH server (192.168.1.22) via port 22 and choose option SSH >Tunnel given in the left column of category.
·         Give new port forwarded as 7000 and connection type as local 
·         Destination address as 192.168.10.2:22 for establishing connection with specific client and click on ADD at last.


 This will establish connection between remote pc and SSH server.


Open new window of putty and follow given below step:
·         Give hostname as localhost and port 7000 and connection type SSH.
·         Click on open to establish connection.


Awesome!! We have successfully access SSH client via port 7000