Skip to content

Instantly share code, notes, and snippets.

@o0-o
Last active June 11, 2022 22:50
Show Gist options
  • Save o0-o/69fa55610d8643a0eeb1d241c3908f47 to your computer and use it in GitHub Desktop.
Save o0-o/69fa55610d8643a0eeb1d241c3908f47 to your computer and use it in GitHub Desktop.
[Enable SSH on a Ubiquiti EdgeRouter via HTTPS] Non-interactively Enable SSH on an EdgeOS Device with cURL #bash #edgemax #edgerouter #edgeos #ubiquit
#!/usr/bin/env bash
ROUTER_IP="192.168.1.1"
COOKIES="$(curl -v "https://${ROUTER_IP}/" \
-H 'Connection: keep-alive' \
-H 'Cache-Control: max-age=0' \
-H "Origin: https://${ROUTER_IP}" \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'DNT: 1' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-User: ?1' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' \
-H 'Sec-Fetch-Site: same-origin' \
-H "Referer: https://${ROUTER_IP}/" \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Accept-Language: en-US,en;q=0.9' \
--data 'username=ubnt&password=ubnt' \
--compressed \
--insecure 2>&1 |
grep "^< Set-Cookie")"
PHP="$(echo "${COOKIES}" | grep "PHPSESSID" | sed 's/.*ID=//' | grep -o "[[:alnum:]]*")"
TOKEN="$(echo "${COOKIES}" | grep "X-CSRF-TOKEN" | sed 's/.*TOKEN=//' | grep -o "[[:alnum:]]*")"
BEAKER="$(echo "${COOKIES}" | grep "beaker.session.id" | sed 's/.*id=//' | cut -d ';' -f 1)"
curl "https://${ROUTER_IP}/api/edge/batch.json" \
-H 'Sec-Fetch-Mode: cors' \
-H "Origin: https://${ROUTER_IP}" \
-H 'Accept-Encoding: gzip, deflate, br' \
-H "X-CSRF-TOKEN: ${TOKEN}" \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'X-Requested-With: XMLHttpRequest' \
-H "Cookie: PHPSESSID=${PHP}; X-CSRF-TOKEN=${TOKEN}; beaker.session.id=${BEAKER}" \
-H 'Connection: keep-alive' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H "Referer: https://${ROUTER_IP}/" \
-H 'Sec-Fetch-Site: same-origin' \
-H 'DNT: 1' \
--data-binary $'{"SET":{"service":{"ssh":"\'\'"}},"GET":{"system":null,"layer2":null,"service":null}}' \
--compressed \
--insecure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment