[cisco-voip] CUCM Bulk TFTP File Upload
Brian Meade
bmeade90 at vt.edu
Fri Jun 1 09:53:50 EDT 2018
Does anyone have a working script for this?
I put together a script in python to do this but hitting some issues.
Right now I’ve got it to the point that it’s trying to upload a single file.
I used Fiddler to copy what I saw for a working request through a browser.
I first do a Get to the cmplatform page to get a cookie.
I then do a Post to the /cmplatform/j_security_check page to authenticate
that cookie.
I then do a Get to /cmplatform/tftpFileUpload.do to get a Struts Token.
I then do a Post to /cmplatform/tftpFileUpload.do with the Struts token,
filename, and directory details.
This looks to be successful as I get a "File uploaded successfully" message
returned but then I can't find the file on the TFTP File Management page.
I tried using the curl methods I found here (
https://communities.cisco.com/docs/DOC-43506 ) but no luck there. Not sure
if this works in 11.5 without grabbing the Struts token. Without a token,
I get an error message saying something to the affect of I hit the Submit
button twice.
Here's what it looks like when my script runs in Fiddler:
This looks almost exactly like the real example through a browser I
captured minus a few headers I tried manually adding with no luck.
Python script attached.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://puck.nether.net/pipermail/cisco-voip/attachments/20180601/a897ce76/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 282511 bytes
Desc: not available
URL: <https://puck.nether.net/pipermail/cisco-voip/attachments/20180601/a897ce76/attachment.png>
-------------- next part --------------
import sys
import requests
from bs4 import BeautifulSoup
import warnings
import os.path
def main(argv):
warnings.filterwarnings("ignore")
hostname= ''
username= ''
password= ''
local_file_path= ''
try:
hostname = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
local_file_path = sys.argv[4]
remote_file_path = sys.argv[5]
except:
print('Please enter hostname/IP Address, username, password, the local file path, and the remote file path')
sys.exit()
s = requests.Session()
payload= {'appNav': 'cmplatform', 'j_username': username, 'j_password': password}
getcookie= s.get('https://' + hostname + '/cmplatform/', verify=False)
post= s.post('https://' + hostname + '/cmplatform/j_security_check', data=payload, verify=False)
tokenrequest= s.get('https://' + hostname + '/cmplatform/tftpFileUpload.do', verify=False)
soup = BeautifulSoup(tokenrequest.text)
try:
token = soup.find('input', {'name': 'token'}).get('value')
except:
print('Couldn''t get token. You may be trying too often.')
sys.exit()
f= open(local_file_path, 'rb')
postfile = s.post('https://' + hostname + '/cmplatform/tftpFileUpload.do', files={'struts.token.name': (None, 'token'),'token': (None, token), 'file': (local_file_path,f,'text/plain'), 'directory': (None, remote_file_path)}, verify = False)
f.close();
if __name__ == "__main__":
sys.argv = ["CUCM-Bulk-TFTP-Upload.py", "hostname", "admin", "hunter2", "testuploadauto.txt", "testuploadauto"]
main(sys.argv[1:])
More information about the cisco-voip
mailing list