-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnk.js
59 lines (43 loc) · 1.42 KB
/
snk.js
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
53
54
55
56
57
58
59
/**
*
* Skeleton for puppeteer pwnage
* Simple auth and take screenshot
*
**/
const { uploadScreenshot } = require("./uploadScreenshot");
const chromium = require('chrome-aws-lambda');
module.exports.pwn = async (event, context, callback) => {
let browser = null;
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: true,
});
// define name for this puppeter action
const screenshot = `snktest-${event.login}`;
const page = await browser.newPage()
// Specify target url
await page.goto('http://x.x.x.x:6969/')
// Set login
await page.click('#username');
await page.keyboard.type(event.login);
// Set password
await page.click('#password');
await page.keyboard.type(event.password);
// click on login button
await page.click('body > div > div > form > button');
// define temp screenshot file
const imagePath = `/tmp/${screenshot}-${new Date().getTime()}.png`;
await page.screenshot({ path: imagePath })
browser.close()
//Debug purpose as usual
console.log(' Login and screenshot done ')
// upload screenshot to S3
const url = await uploadScreenshot(imagePath, screenshot);
// Return URL where screenshot is stored on S3 bucket
//return url;
//return result;
console.log('result: ' + url )
callback(null, url);
};