Last active
March 24, 2023 15:59
-
-
Save selboo/9eb0d8b25cd71ea31c319b23ad94cd6e to your computer and use it in GitHub Desktop.
python openvpn
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 | |
import pyotp | |
import sys,os | |
import re | |
import MySQLdb | |
def DB_Check(User, Pass): | |
db = MySQLdb.connect( | |
host="192.168.20.33", | |
port=3306, | |
user="root", | |
passwd="123456", | |
db="openvpn", | |
cursorclass=MySQLdb.cursors.DictCursor | |
) | |
try: | |
cursor = db.cursor() | |
cursor.execute("SELECT salt FROM admin WHERE name = '%s' and pass = '%s' " %(User, Pass)) | |
data = cursor.fetchone() | |
except: | |
return False, 2 | |
if len(data) == 0: | |
return False, 1 | |
salt = data.get('salt', False) | |
if not salt: | |
return False, 1 | |
return salt, 0 | |
def Goog_Check(Code, Salt): | |
totp = pyotp.TOTP(Salt) | |
if totp.now() != Code: | |
return False, 1 | |
return True, 0 | |
def Read_File(oFile): | |
rErun_NP = [] | |
try: | |
oFile_NP = open(oFile, 'r') | |
for line in oFile_NP: | |
rErun_NP.append(line.strip('\n')) | |
except: | |
return 1, 1, 1, 1 | |
else: | |
oFile_NP.close() | |
try: | |
User = rErun_NP[0] | |
Pass = re.findall(r"\S+(?=[0-9]{6}$)",rErun_NP[1])[0] | |
Code = re.findall(r"[0-9]{6}$",rErun_NP[1])[0] | |
except: | |
return 2, 2, 2, 2 | |
return User, Pass, int(Code), 0 | |
if __name__ == '__main__': | |
User, Pass, Code, Err = Read_File(sys.argv[1]) | |
if Err != 0: | |
print "file failed" | |
sys.exit(1) | |
print User | |
print Pass | |
print Code | |
Salt, Err = DB_Check(User, Pass) | |
if Err != 0: | |
print "db authentication failed" | |
sys.exit(1) | |
Ok, Err = Goog_Check(Code, Salt) | |
if Err != 0: | |
print "google authentication failed" | |
sys.exit(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment