Is it possible to write a Python (iOS) program to allow/execute commands to a RaspberryPi?

262 views Asked by At

I am currently underway with my Senior Capstone project, in which I am to write a somewhat basic program which allows a custom interface on my iPhone6 device to remotely control or issue critical commands to a NIDS (Suricata) established at my home RaspberryPi(3B+) VPN. My question, however, is whether it's feasible to write said program which can allow remote access control of basic functions/response options on the Pi's IDS, given that I am utilizing it as a device within the VPN network. The main issue would be establish remote signaling to the iOS device whenever there is an anomaly and allowing it to respond back and execute root-level commands on the NIDS.

If it is of any good use, I am currently using Pythonista as a runtime environment on my mobile device and have set my VPN's connection methods to UDP, but I'm not sure if enabling SSH would assist me. I have a rather basic understanding of how to operate programming in regards to network connectivity. I very much appreciate any and all the help given!

from tkinter import *
window=Tk()
window.geometry("450x450")
window.title("IDS Response Manager")

label1=Label(window,text="Intrusion Response Options",fg= 'black',bg ='white',relief="solid",font=("times new roman",12,"bold"))
label1.pack()

button1=Button(window,text="Terminate Session",fg='white', bg='brown',relief=RIDGE,font=("arial",12,"bold"))
button1.place(x=50,y=110)      #GROOVE ,RIDGE ,SUNKEN ,RAISED

button2=Button(window,text="Packet Dump",fg='white', bg='brown',relief=RIDGE,font=("arial",12,"bold"))
button2.place(x=220,y=110)      #GROOVE ,RIDGE ,SUNKEN ,RAISED

button3=Button(window,text="Block Port",fg='white', bg='brown',relief=RIDGE,font=("arial",12,"bold"))
button3.place(x=110,y=170)      #GROOVE ,RIDGE ,SUNKEN ,RAISED

Very basic options as are shown here.

1

There are 1 answers

0
KetZoomer On

You can use a flask server with an API, which you can send post requests to. You can then send get requests to receive the commands. To host your API, look at Heroku (free tier available, and very much functional, with already configured app_name.herokuapp.com).

Search up to send a post request with the technologies you are using to build your app. Send keyword command with the command to the /send_commands along with the password, "password_here" (changeable to anything you want).

Python:

Modules: Flask (server), request (client)

Server Code:

from flask import Flask

app = Flask(__name__)

commands = []

@app.route('/get_commands', methods=['GET'])
def get_commands():
    tmp_commands = commands[::]
    commands = []
    return {'commands': tmp_commands}

@app.route('/send_commands', methods=['POST'])
def send_commands():
    if request.json['password'] == "password_here":
        commands.append(request.json['command'])
        return {'worked': True}
    else:
        return {'worked': False}

if __name__ == '__main__':
    app.run(debug=True)

Client Code:

import requests 
  
URL = "url_here/get_commands"

commands = requests.get(url = URL) 

for command in commands:
    os.system(command)