Skip to content

Instantly share code, notes, and snippets.

@make-github-pseudonymous-again
Created May 24, 2019 08:09
Show Gist options
  • Save make-github-pseudonymous-again/367c539e8637a5df77f201b5a947b5b6 to your computer and use it in GitHub Desktop.
Save make-github-pseudonymous-again/367c539e8637a5df77f201b5a947b5b6 to your computer and use it in GitHub Desktop.
Attempt at querying the TP-link Archer C3200 API
const puppeteer = require('puppeteer');
async function main () {
// Create browser instance, and give it a first tab
const options = {
executablePath: '/usr/bin/chromium' ,
//headless: false, // debug
//slowMo: 250, // debug
} ;
const browser = await puppeteer.launch(options);
const page = await browser.newPage();
// Allows you to intercept a request; must appear before
// your first page.goto()
await page.setRequestInterception(true);
await page.setExtraHTTPHeaders({
"Host: $HOST" \
'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0' \
'Accept: */*' \
'Accept-Language: en-US,en;q=0.8,fr;q=0.5,ja;q=0.3' \
'Accept-Encoding: gzip, deflate' \
"Referer: http://192.168.1.1/" \
'Content-Type: text/plain' \
'DNT: 1' \
'Connection: keep-alive' \
"Cookie: Authorization=Basic ${secret}" \
'Pragma: no-cache' \
'Cache-Control: no-cache' \
'Upgrade-Insecure-Requests: 1'
});
// Request intercept handler... will be triggered with
// each page.goto() statement
page.on('request', interceptedRequest => {
// Here, is where you change the request method and
// add your post data
var data = {
'method': 'POST',
'postData': '[LAN_HOST_ENTRY#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n'
};
// Request modified... finish sending!
interceptedRequest.continue(data);
});
// Navigate, trigger the intercept, and resolve the response
const response = await page.goto('http://192.168.1.1/cgi?5');
const responseBody = await response.text();
console.log(responseBody);
// Close the browser - done!
await browser.close();
}
main().catch( err => {
console.log(err) ;
process.exit(100) ;
}) ;
@make-github-pseudonymous-again
Copy link
Author

I seem unable to replicate firefox's AJAX requests. I always get an error response. The puppeteer script was never finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment