Jump to content

Adding SSID with API creates strange SSID names


Keld Norman

Recommended Posts

I made this script..  ( see below ) and a file that contains the SSID names I want to add.

When i run it it adds the SSID names as expected but also some strange chars and names appears like there is an error that happens when using the API:

<img src="https://www.lostserver.com/static/pineapple_api_error.png" alt="API ERROR">

Do you know why this error happens ? ( see image - first SSID name)

I run the script like this:

root@router:~/source/Pineapple# ./add_ssid.sh ./add_ssid.list

⠀⠀⢠⡾⠃⠀⠀⠀⠀⠀⠀⠰⣶⡀⠀⠀
⠀⢠⡿⠁⣴⠇⠀⠀⠀⠀⠸⣦⠈⢿⡄⠀ This script adds
⠀⣾⡇⢸⡏⢰⡇⠀⠀⢸⡆⢸⡆⢸⡇⠀  SSID NAMES to
⠀⢹⡇⠘⣧⡈⠃⢰⡆⠘⢁⣼⠁⣸⡇⠀   a PINEAPPLE
⠀⠈⢿⣄⠘⠃⠀⢸⡇⠀⠘⠁⣰⡟⠀
⠀⠀⠀⠙⠃⠀⠀⢸⡇⠀⠀⠘⠋⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠘⠃⠀⠀
 
 Detecting WiFi Pineapple link           [OK]
 Waiting for ping reply from Pineapple   [OK]
 Generating API key on the Pineapple     [OK]
 -----------------------------------------------------------------------------------
 Importing 19 SSID's..
 -----------------------------------------------------------------------------------
 Adding SSID: ADM                                                              [OK]
 Adding SSID: ADMIN_Network                                                    [OK]
 Adding SSID: AIRPORT                                                          [OK]
 Adding SSID: AIRPORT FREE WIFI                                                [OK]
 Adding SSID: AIRPORT-FREE-WiFi                                                [OK]
 Adding SSID: AK-intern                                                        [OK]
 Adding SSID: AK-net                                                           [OK]
 Adding SSID: APMM_HOTSPOT                                                     [OK]
 Adding SSID: ATEA-GUEST                                                       [OK]
 Adding SSID: AirPort                                                          [OK]
 Adding SSID: Airport Free WiFi                                                [OK]
 Adding SSID: Airport-Guest                                                    [OK]
 Adding SSID: Airport_Free_WiFi_AENA                                           [OK]
 Adding SSID: Alibaba                                                          [OK]
 Adding SSID: All Station Guests                                               [OK]
 Adding SSID: Apple Demo                                                       [OK]
 Adding SSID: Apple Store                                                      [OK]
 Adding SSID: Arlanda Express                                                  [OK]
 Adding SSID: Airport1                                                         [OK]
 -----------------------------------------------------------------------------------
 2022-10-01T17:43:02 CEST - End of import!
 -----------------------------------------------------------------------------------

root@router:~/source/Pineapple# cat add_ssid.list

ADM
ADMIN_Network
AIRPORT
AIRPORT FREE WIFI
AIRPORT-FREE-WiFi
AK-intern
AK-net
APMM_HOTSPOT
ATEA-GUEST
AirPort
Airport Free WiFi
Airport-Guest
Airport_Free_WiFi_AENA
Alibaba
All Station Guests
Apple Demo
Apple Store
Arlanda Express
AirportX


root@router:~/source/Pineapple# cat add_ssid.sh

#!/bin/bash
# set -x
clear
#-----------------------------
# (C)opyleft Keld Norman 2022
# Twitter: @keld_norman
# Youtube : https://www.youtube.com/c/KeldNorman
# Manual for the Pineapple: https://hak5.github.io/mk7-docs/
#----------------------------------------------------------------------------
# VARIABLES
#----------------------------------------------------------------------------
PINEAPPLE_IP="172.16.42.1"
PINEAPPLE_PASSWORD="PineapplePasswordHere"
#----------------------------------------------------------------------------
# BANNER FOR THE 1337'ishness
#----------------------------------------------------------------------------
cat << "EOF"

⠀⠀⢠⡾⠃⠀⠀⠀⠀⠀⠀⠰⣶⡀⠀⠀
⠀⢠⡿⠁⣴⠇⠀⠀⠀⠀⠸⣦⠈⢿⡄⠀ This script adds
⠀⣾⡇⢸⡏⢰⡇⠀⠀⢸⡆⢸⡆⢸⡇⠀  SSID NAMES to
⠀⢹⡇⠘⣧⡈⠃⢰⡆⠘⢁⣼⠁⣸⡇⠀   a PINEAPPLE
⠀⠈⢿⣄⠘⠃⠀⢸⡇⠀⠘⠁⣰⡟⠀
⠀⠀⠀⠙⠃⠀⠀⢸⡇⠀⠀⠘⠋⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠘⠃⠀⠀
 
EOF
#----------------------------------------------------------------------------
# PRE CHECKS
#----------------------------------------------------------------------------
if [ ! -x /usr/bin/curl ]; then
 printf "\n ### ERROR - Missing curl utility (apt-get install curl)\n\n"
 exit
fi
if [ ! $# -eq 1 ]; then
 printf "\n ### ERROR - Missing file containing SSID names as parameter\n\n"
 printf " Syntax is: $0 [/path/to/file/with/ssid/names.xxx]\n\n"
 exit 1
fi
if [ ! -s $1 ]; then
 printf "\n ### ERROR - The SSID list file is missing or empty ($1)\n\n"
 exit 1
fi
#----------------------------------------------------------------------------
# Set the Pineapple IP
#----------------------------------------------------------------------------
printf " %-40s" "Detecting WiFi Pineapple link"
until ip addr|grep link|awk '{print $2}'|egrep -c -e "00:13:37|00:[cC]0:[cC][aA]" > /dev/null
 do
  sleep 1
 done
echo "[OK]"
#-------------------------------------------------------------
printf " %-40s" "Waiting for ping reply from Pineapple"
#-------------------------------------------------------------
until ping -c1 -w1 ${PINEAPPLE_IP} >/dev/null
do
 printf "."
 sleep 1
done
echo "[OK]"
#----------------------------------------------------------------------------
# GET A TOKEN FROM THE PINEAPPLE
#----------------------------------------------------------------------------
printf " %-40s" "Generating API key on the Pineapple"
TOKEN=$(curl -X POST http://${PINEAPPLE_IP}:1471/api/login -d "{\"username\": \"root\", \"password\": \"$PINEAPPLE_PASSWORD\"}" 2>/dev/null|grep "token"|cut -d '"' -f4)
if [ -z "${TOKEN}" ]; then
 echo "[ERROR]"
 printf "\n ### ERROR - Failed to get an API token!\n\n"
 exit 1
fi
echo "[OK]"
#----------------------------------------------------------------------------
# Import the SSIDS
#----------------------------------------------------------------------------
printf -- " -----------------------------------------------------------------------------------\n"
printf " Importing $(cat $1|wc -l) SSID's..\n"
printf -- " -----------------------------------------------------------------------------------\n"
cat ${1}|grep -v ^#|while read SSID; do
 SSID_SAFE="${SSID}"
 printf " Adding SSID: %-64s" "${SSID_SAFE}"
 STATUS=$(\
  curl --silent \
       -X PUT \
       -H "Content-type: application/json" \
       -H "Authorization: Bearer ${TOKEN}" \
       -d '{"ssid":"'"${SSID_SAFE}"'"}' \
       "http://${PINEAPPLE_IP}:1471/api/pineap/ssids/ssid")
 HOW_DID_IT_GO=$(echo ${STATUS}|grep -c '{"success":true}')
 if [ ${HOW_DID_IT_GO:-0} -eq 1 ]; then
  echo " [OK]"
 else
  printf " [FAILED] - ${STATUS}\n"
 fi
done
printf -- " -----------------------------------------------------------------------------------\n"
printf " $(date) - End of import!\n"
printf -- " -----------------------------------------------------------------------------------\n\n"

 

Link to comment
Share on other sites

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.

  • Recently Browsing   0 members

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