Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * HACK.ART Demo 1
- * by tchnmncr @ hyperritual.com
- *
- * This is a Processing sketch demonstrating interaction with
- * Hak5's WiFi Pineapple and Arduino.
- * For more info see
- * http://hyperritual.com/blog/hack-art-wifi-pineapple-processing-arduino.
- *
- * Made with Processing 3.2.1.
- */
- import http.requests.*;
- import processing.serial.*;
- String API_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
- PostRequest startScan, // POST to initiate scan
- scanStatus; // POST to retrieve scan results
- Serial arduino; // Arduino serial port
- void setup() {
- size(640, 640);
- background(50);
- fill(200);
- noStroke();
- noLoop(); // I am running through the draw() loop once only and using delay(); in reality you would probably
- // repeat through it with a timer and use millis() to create a delay between scans
- String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
- arduino = new Serial(this, portName, 9600);
- }
- void draw() {
- /*** Instruct the Pineapple to perform a 15-second scan for only access points (no clients) ***/
- // build and send the POST request
- // {
- // "module": "Recon",
- // "action": "startScan",
- // "scanType": "apOnly",
- // "scanDuration": "15"
- // "apiToken": API_TOKEN
- // }
- PostRequest startScan = new PostRequest("http://172.16.42.1:1471/api/");
- startScan.addHeader("Content-Type", "application/json");
- startScan.addJson("{\"module\":\"Recon\",\"action\":\"startScan\",\"scanType\":\"apOnly\",\"scanDuration\":\"15\",\"apiToken\":\"" + API_TOKEN + "\"}");
- startScan.send();
- // wait 20 seconds for scan to complete; I am only using this with noLoop();
- // otherwise, you could continue to send() until the response includes "completed":true
- delay(20000);
- // get the POST response
- String startScanResponse = startScan.getContent();
- String startScanResponseClean = startScanResponse.substring(6); // strip off ")]}',"
- // create a JSON object from the POST response
- JSONObject jsonStartScan = parseJSONObject(startScanResponseClean);
- // check to see if scan was successful
- if (jsonStartScan.getBoolean("success") == false) {
- println("There was a problem requesting the scan.");
- return; // break out of draw() loop if scan failed
- }
- // get scan ID from JSON object
- int scanId = jsonStartScan.getInt("scanID");
- /*** Retrieve scan results from the Pineapple ***/
- // build and send the POST request
- // {
- // "module": "Recon",
- // "action": "scanStatus",
- // "scanID": scanId,
- // "apiToken": API_TOKEN
- // }
- PostRequest scanStatus = new PostRequest("http://172.16.42.1:1471/api/");
- scanStatus.addHeader("Content-Type", "application/json");
- scanStatus.addJson("{\"module\":\"Recon\",\"action\":\"scanStatus\",\"scanID\":" + scanId + ",\"apiToken\":\"" + API_TOKEN + "\"}");
- scanStatus.send();
- // get the POST response
- String scanStatusResponse = scanStatus.getContent();
- String scanStatusResponseClean = scanStatusResponse.substring(6); // strip off ")]}',"
- // create a JSON object from the POST response
- JSONObject jsonScanStatus = parseJSONObject(scanStatusResponseClean);
- // further parse the JSON data
- JSONObject results = jsonScanStatus.getJSONObject("results");
- JSONArray apList = results.getJSONArray("ap_list");
- // write the BSSID (MAC) and power (dBm) values to arrays
- String[] bssid = {};
- int[] power = {};
- for (int i = 0; i < apList.size(); i++) {
- JSONObject ap = apList.getJSONObject(i);
- bssid = append(bssid, ap.getString("bssid"));
- power = append(power, ap.getInt("power"));
- }
- /*** Draw rectangles representing access points ***/
- // calculate height of all rectangles according to total # of access points
- float h = (height * 1.0) / bssid.length;
- for (int i = 0; i < bssid.length; i++) {
- // set rectangle's color based on first three octets of MAC
- int r = unhex(bssid[i].substring(0, 2));
- int g = unhex(bssid[i].substring(3, 5));
- int b = unhex(bssid[i].substring(6, 8));
- fill(r, g, b);
- // calculate length of rectangle according to its power (in dBm)
- float l = map(100 + power[i], 0, 100, 0, width);
- rect(0, h * i, 100 + l, h);
- }
- /*** Send a signal to Arduino if target BSSID was found in scan ***/
- String target = "00:FF:00:FF:00:FF"; // replace with target BSSID
- boolean targetFound = false;
- // loop through bssid array, searching for target
- for (int i = 0; i < bssid.length; i++) {
- if (bssid[i].equals(target)) {
- targetFound = true;
- break;
- }
- }
- if (targetFound == true) {
- arduino.write('1');
- println("Target found!");
- } else {
- arduino.write('0');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement