Last active
July 20, 2022 13:06
-
-
Save AKSarav/299b83d3502f4518cb6b807bdc1ccefc to your computer and use it in GitHub Desktop.
SecureCLI-Curl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# | |
# Author: [email protected] | |
# Name: SecureCLI-Curl.py | |
# Date: 27-March-2018 | |
# | |
# | |
import os | |
import sys | |
import getpass | |
import time | |
import base64 | |
import subprocess | |
import re | |
text=[] | |
output = "" | |
print "-"*90 | |
print "\t\t Secure CLI for CURL - No more clear text password" | |
print "-"*90 | |
print "Instrutions\n------------" | |
print "This is Secure CLI for CURL tool created to efficiently pass the username and password to CURL" | |
print "Now you will be prompted for username & password" | |
print "After Entering the username and password you DO NOT have to use --user username:password in your request header" | |
print "The Tool will take care of passing the credentials as a Authorization header" | |
print "Note*: Your details will not be saved and only valid for this session" | |
print "\nExample:" | |
print "--------" | |
print " curl -v \ " | |
print " -H X-Requested-By:MyClient \ " | |
print " -H Accept:application/json \ " | |
print " -X GET http://localhost:7001/management/weblogic/latest/serverConfig?links=none " | |
print " END" | |
print "-"*90 | |
# Get username and password | |
username = raw_input("Enter the Username: ") | |
password=getpass.getpass("Enter the Password: ") | |
cred_enc=base64.b64encode(username+":"+password) | |
print "INFO: the entered user credentials have been encrypted and will be sent as a header" | |
#cred_dec=base64.b64decode(cred_enc) | |
#print cred_dec | |
def makerequest(): | |
print "" | |
print "Enter the whole request line by line, type END and hit enter once done" | |
#read -d '' i << END | |
while True: | |
line=raw_input("") | |
text.append(line) | |
if "END" in line: | |
break | |
text.pop() | |
#update the basic auth header | |
text.insert(1,'-H "Authorization: Basic '+cred_enc+'"') | |
cmd = " ".join(text) | |
cmd=re.sub('[\\\]','', cmd) | |
print "==========================" | |
print "Execution Result" | |
print "==========================" | |
print "" | |
output = subprocess.Popen([cmd], shell=True, stdout = subprocess.PIPE).communicate()[0] | |
print output | |
print "" | |
print "==========================" | |
makerequest() | |
while True: | |
ans=raw_input("Would you like to Proceed and Make a New Request ? Yes to Continue| No to exit : ") | |
if "y" in ans or "Y" in ans or "yes" in ans or "Yes" in ans or "YES" in ans: | |
text=[]; | |
makerequest() | |
else: | |
sys.exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment