Developer

last person joined: 6 days ago 

Expand all | Collapse all

SSID pw change

This thread has been viewed 4 times
  • 1.  SSID pw change

    Posted Oct 23, 2018 07:44 AM

    Hi,

    i'm trying to change a SSID WPA2 Key by a python Script.

    What i got til now:

    - login to our Mobility Master.

    - figure out the Cookie ID -> not the best way but it works ^^

    - Logout (see attachment)

     

    Now i tried out to post a new password with a curl command at the api gui.

    ->that works, but only if i safe the "Pending Changes" at the main gui.

     

    So you guys know how to post a curl command like this in pyhton? (attachment)

     

    It it also necessary to safe changes (After the post command) by script?

     

    Thanks

    Dany

     

     

     

    Attachment(s)

    txt
    PW_Change.txt   1 KB 1 version
    txt
    CURL_TXT.txt   4 KB 1 version


  • 2.  RE: SSID pw change

    Posted Oct 23, 2018 08:37 AM

    Hey man,

     

    Here is how to access your cookie in a more sane way:

     

    l = json.loads(login.content)
    cookie = l['_global_result']['UIDARUBA']


  • 3.  RE: SSID pw change

    EMPLOYEE
    Posted Oct 23, 2018 09:17 AM

    I think you'll need to save as well, essentially commiting the 'Pending Changes', you can do that with a write mem:

     

    wm_call = session.post(
    "{}configuration/object/write_memory?config_path=%2Fmd&UIDARUBA={}".format(url, cookie)


  • 4.  RE: SSID pw change

    Posted Oct 24, 2018 03:57 AM
      |   view attached

    Hey,

     

    thanks for the feedback :)

     

    So i modifyed the script and deployed it without an error (except for the https InsecureRequestWarning )

     

    But my SSID "Test_PW" didn't change the WPA2 Key....is my playload right? Or is there a better way to change a WPA2 Key by script?

     

     

    Attachment(s)

    txt
    PW_Change.txt   1 KB 1 version


  • 5.  RE: SSID pw change

    Posted Oct 24, 2018 04:00 AM

    For each post you make against the API you should get a reply back.

    Paste the content here, maybe it reveals some clues.



  • 6.  RE: SSID pw change

    Posted Oct 24, 2018 04:40 AM

     

     

    for the wm_call post i get:

    b'{
      "write_memory": {
        "_result": {
          "status": 0,
          "status_str": "Success"
        }
      },
      "_global_result": {
        "status": 0,
        "status_str": "Success",
        "_pending": false
      }
    }'

     

    for the create_PW i get this error:

    b'{
      "Error": "Exception raised while processing request"
    }'

     

    for both i get the status code "200"

     

    maybe a fundamental error?

     

     

     



  • 7.  RE: SSID pw change

    Posted Oct 24, 2018 07:41 AM

    Hey, 

    Try this (written for python 2.7)

     

    import requests
    import json
    
    #EDIT THESE VARIABLES
    #IP, username and PW for MM authentication
    ip = 'ip'
    username = 'username'
    password = 'password'
    
    #current ssid_profile name you want to edit
    ssid_prof_name = 'ssid_profile_name'
    
    #new password for SSID
    new_psk = 'new_psk_here'
    #%2F replaces slash (below converts to /md/FOLDER1) config_path = '%2Fmd%2FFOLDER1' #END baseURL = 'https://{}:4343/v1'.format(ip) auth = {'username': username, 'password': password} s = requests.Session() login = s.post('{}/api/login'.format(baseURL), data=auth, verify=False) loginData = json.loads(login.content) cookie = loginData['_global_result']['UIDARUBA'] payload = { "ssid_prof": [ { "profile-name": ssid_prof_name, "_action": "add", "wpa_passphrase": { "wpa-passphrase": new_psk, "_action": "add" } } ] } data_set = s.post('{}/configuration/object?config_path={}&UIDARUBA={}'.format(baseURL, config_path, cookie), json=payload, verify=False) print data_set.content

    Note that there is no logout or commit posts in above code, but you've figured that out already :)



  • 8.  RE: SSID pw change

    EMPLOYEE
    Posted Oct 24, 2018 04:15 PM

    In dataset this:

     

    data=json.dumps(payload)

     

    Can just be:

     

    json=payload



  • 9.  RE: SSID pw change

    Posted Oct 25, 2018 02:33 AM

    Oh yeah, didnt think of that. Edited :)



  • 10.  RE: SSID pw change

    Posted Oct 26, 2018 03:50 AM

    Hey,

     

    thanks for your support!

    So i added the script from dojjan.

     

    The script is doning well and i get no errors :)

    But i figured out two problems:

    1.

    the changes will not be saved. If i take a look at the MM Webinterface, it offers me the "pending changes" button . But if i execute the script, go to the api webinterface and  do the post command:

    https://IP_MM:4343/v1/configuration/object/write_memory?config_path=%2Fmd%2FTB&UIDARUBA=5e4b0198-cff4-476d-aadf-a427c24e2511

    the changes will be saved.

    Are the any bugs in my postcommad? Or is it necessary to do the "wr_mem" in a separate script?

     

    2. How do i kick out connected users of the SSID? The SSID is only for guests and should change daily.

     

    I hope you can help me a nother time ;)

     

    Thanks

     

     

     
    import requests
    import json
    
    #EDIT THESE VARIABLES
    #IP, username and PW for MM authentication
    ip = 'ip'
    username = 'username'
    password = 'password'
    
    #current ssid_profile name you want to edit
    ssid_prof_name = 'Test_PW'
    
    #new password for SSID
    new_psk = '123456789'
    
    #%2F replaces slash (below converts to /md/TB)
    config_path = '%2Fmd%2FTB'
    #END
    
    baseURL = 'https://{}:4343/v1'.format(ip)
    
    auth = {'username': username, 'password': password}
    
    s = requests.Session()
    login = s.post('{}/api/login'.format(baseURL), data=auth, verify=False)
    loginData = json.loads(login.content)
    
    cookie = loginData['_global_result']['UIDARUBA']
    
    
    
    payload = {
        "ssid_prof": [
            {
            "profile-name": ssid_prof_name,
            "_action": "add",
            "wpa_passphrase": {
                "wpa-passphrase": new_psk,
                "_action": "add"
            }
            }
        ]
        }
    
    
    data_set = s.post('{}/configuration/object?config_path={}&UIDARUBA={}'.format(baseURL, config_path, cookie), json=payload, verify=False)
    
    print(data_set.content)
    
    
    
    wm_call = s.post("{}configuration/object/write_memory?config_path={}&UIDARUBA={}".format(baseURL, config_path, cookie))
    
    print(wm_call.content)
    
    
    logout =  s.post('{}/api/logout'.format(baseURL), data=auth, verify=False)
    print("Logout Status: ", logout.status_code)
    print("############################")
    print("############################")

     



  • 11.  RE: SSID pw change

    MVP GURU
    Posted Oct 26, 2018 04:00 AM

    if you change the PSK, the user will be disconnect...



  • 12.  RE: SSID pw change

    Posted Oct 26, 2018 04:08 AM

    Hey,

     

    What is the content of 

    print(wm_call.content)

    I might believe it's because you are not using a proper SSL-certificate and you have not set verify=False in your write mem post.

     

    Try this

     

    wm_call = s.post("{}configuration/object/write_memory?config_path={}&UIDARUBA={}".format(baseURL, config_path, cookie), verify=False)

     



  • 13.  RE: SSID pw change

    Posted Oct 26, 2018 04:41 AM

    the contet of wm_call is:

     

    Python\Python37-32\lib\site-packages\urllib3\connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

     

    i added the verify but the issure and massages are the same....

     



  • 14.  RE: SSID pw change
    Best Answer

    Posted Oct 26, 2018 04:55 AM

    Oh wait, there is a missing slash after baseURL, try this:

     

    wm_call = s.post("{}/configuration/object/write_memory?config_path={}&UIDARUBA={}".format(baseURL, config_path, cookie), verify=False)


  • 15.  RE: SSID pw change

    Posted Oct 26, 2018 05:04 AM

    ahhhhhh that works!!!

     

    Thanks a lot :)



  • 16.  RE: SSID pw change

    EMPLOYEE
    Posted Oct 26, 2018 06:04 AM

    Ah, ok different approach, I should have checked that.

    When I'm creating the baseurl variable, I have the trailing '/' when the variable is created, so for example:

     

    url = 'https:<ipadd>/rest/v1/' 

    Rather than:

     url = 'https:<ipadd>/rest/v1'

     

    Trailing '/' is always needed so why include the additional character every time the url is called?

    I've just had a look on github at popular rest api python wrapper for any consensus on this. The first one had the first example, but the second used my approach. So, a matter of style choice I guess. Unless someone knows of some style guidelines, PEP8 doesn't say anything about this, but does say consistency is important. So pick one approach and stick with it in your project.

     

     



  • 17.  RE: SSID pw change

    Posted Oct 26, 2018 06:11 AM

    @joeneville

     

    I agree 100%.

    I did not put much thought into this, just wanted him to have a working example :)

    The code itself is such a mess, hehe.