Jump to content

PHP Curl to pineapple API


sebaz

Recommended Posts

Posted

Hi!

I am trying to build a new webinterface for the pineapple, because I want to use the device to teach people how vulnerable they are. I want to use the pineapple API for this, using PHP to call the functions on my pineapple via cURL. I have the following code:

 

Quote

<?php
//display errors, remove when done
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);

$key="apiToken";

//define POST & encode in JSON

$a=[
    'system'=>'notifications',
    'action'=>'addNotification',
    'message'=>'Hello from apache!',
    'apiToken'=>'7de64925dd8703fc5595a7d0b845ce0ed965fa799b67a19b310cb2538017aeaacb205e6dbc72d8758c3b995d25a1a273783c49bfb7519b2e71fbd49af074ab35'
];

$JSON = json_encode($a);
print $JSON;

//curl post request
$c = curl_init();
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_URL, "http://172.16.42.1:1471/api");
//curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $JSON);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: ' . $key
));

//print curl output
$result = curl_exec($c);
print $result;
$info = curl_getinfo($c);
print '</br>';
print $info['http_code'];
if(!curl_exec($c)){
    die('Error: "' . curl_error($c) . '" - Code: ' . curl_errno($c));
}
    curl_close($c);
 

When I execute this code, i'll get bag a '200' http code. All good right? However, the server output is 'not authenticated' and nothing happens on the pineapple, no notification appears.

 

Does anybody have any idea what I'm doing wrong?

  • 1 month later...
Posted

turns out, the url has to have a '/' at the end.

 

It works when you use:

curl_setopt($c, CURLOPT_URL, "http://172.16.42.1:1471/api/");

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...