Jump to content

PHP Curl to pineapple API


sebaz
 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

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