So the issue is we have an openLDAP server for authentication of our NAS drives in the office. Every time a computer is restarted the user has to input their password again to access the drives. Simply running a batch script to log into their drives in the morning works but the big boss doesn't like that their passwords are just sitting in raw text in the file.
So I've been plugging away in python to try and get a simple program to retrieve their password from windows credentials and toss that into a NET USE in os.system:
os.system("net use X: \\\\x.x.x.x password /user:username#domain.com")
I can retrieve the user name from a file simply enough from a variable opening a file and reading from a line. The issue is the password.
test_a = open('passtest.cfg', 'r')
test_b = open('passtest2.cfg', 'r')
test2_a = test_a.readline()
test2_b = test_b.readline()
drivepass = keyring.get_password(test2_a, test2_b)
The issue seems to be that keyring doesn't like reading from variables for some reason or another. At least i can't seem to figure out why it doesn't. It works just fine if i use:
drivepass = keyring.get_password("x.x.x.x", "username#domain.com")
The REAL problem is we need it simple enough that we can just move it around from workstation to workstation and just change the username#domain.com in a file and run it. So in the end the end product looks something like
os.system("net use X: \\\\x.x.x.x\foldername" + drivepass + "/user:" + test2_b)
It seems I've accidentally solved my own problem.
Didn't work:
drivepass = keyring.get_password(test2_a, test2_b)
Works:
drivepass = keyring.get_password("x.x.x.x", test2_b)
So the service arg in keyring apparently needs to not be a variable. to be fair though it doesn't need to be anyways. Hopefully somewhere down this line this helps somebody else.
Related
I'm sorry, I'm as new to programming as can be (I have a sys-admin background but I'm really interested in the development side of problem solving). If I ask illogical questions or I'm not posting how I should, please understand I'm trying to learn and I'm very open to corrections.
TLTR: I'm very new and heavily modified a Python 2.7 code I found online years ago for a method to "lock" windows folders. I'm looking to update my app/program to utilize tKinter to replace the current command prompt password entry process in place but lack the programming knowledge for logically what I'm missing.
How it works functional:
Run the .exe (I converted the .py file not knowing I could run easy by changing extension from py to .pyw, again very new)
Pop-up prompt requests password (not tKinter, just a command prompt box I customized the size, banner, and prompt for)
When correct password is entered, a folder that is hidden elsewhere on the PC becomes unhidden, the name changes, and it appears on the desktop. (If no folder was created in the first place, it will create one; not included in code below.)
After files are added, the same password can be entered which changes the desktop folder's attribute to be hidden and placed back to the hidden location
If password fails, the pop-up prompt states there's an incorrect password then loops back to the password entry. (Left this part out below as idk how much code I should be giving)
import base64
import os
import time
import sys
import getpass
import shutil
#Set Password
pw = "p#ssword"
encode = base64.b64encode(pw)
#Custom window size
os.system("mode con: cols=40 lines=4")
def goto(linenum):
global line
line = linenum
line = 1
while True:
#Customizable welcome banner
print "****************************************"
print " Welcome:"
print "****************************************"
pw = (getpass.getpass('Password: '))
pass
goto(1)
#Hides password input
if pw == base64.b64decode(encode):
# Sets the path where you want BitLocker to show up
os.chdir("C:\Users\WINUSER\Desktop")
#Checks for existing BitLocker folder
if not os.path.exists("BitLocker"):
#If BitLocker folder isn't found, it checks for BitLocker.{CLSID}
if not os.path.exists("BitLocker.{A0953C92-50DC-43bf-BE83-3742FED03C9C}"):
#If BitLocker.{CLSID} isn't found on Desktop, it changes the folder name in hidden location to BitLocker, unhides it and moves it back to the desktop
os.rename("C:\\Users\\WINUSER\\Videos\\Captures\\BitLocker.{A0953C92-50DC-43bf-BE83-3742FED03C9C}", "C:\\Users\\WINUSER\\Desktop\\BitLocker.{A0953C92-50DC-43bf-BE83-3742FED03C9C}")
os.popen('attrib -h BitLocker.{A0953C92-50DC-43bf-BE83-3742FED03C9C}')
os.rename("BitLocker.{A0953C92-50DC-43bf-BE83-3742FED03C9C}","BitLocker")
I'm looking to add a tKinter GUI that works as a password entry than does the folder moves, etc. Would it be better to have 2 programs, 1 tKinter for a PW entry prompt that, when entered correct, calls to open another program to change the folder's attributes?
I've been seen code like what's below on here, but don't know how to incorporate it into what I currently have. I'm not too proud to be pointed towards documentation.
from tkinter import *
def show():
p = password.get() #get password from entry
print(p)
app = Tk()
password = StringVar() #Password variable
passEntry = Entry(app, textvariable=password, show='*')
submit = Button(app, text='Show Console',command=show)
passEntry.pack()
submit.pack()
app.mainloop()
Thank you
I think the question speaks for itself. I have trouble getting some values out of the registry, and I was hoping someone around here might help me.
I'm stuck at IE9, as it is the only one which has some reasonable CSS capabilities, and does support GetObject().
So right now, lets say I'm trying to retrieve the memory size of a GPU at "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000\HardwareInformation.qwMemorySize" (as far as I know, this should be a universal path & key).
This is where the problem begins. Either I get no output, or some error saying something is different, or what (my system is running in a different language so I cant offer the right translation).
After some research, I seem to have found the issue - the value I'm trying to read is REG_QWORD, and unfortunately I was only able to find very little covering this topic, and most of the solutions did not work for me.
So right now, I am with this code, which, unsurprisingly, also does not work (the code I had since like the beginning):
for Each oItem in colGPUs
memory = oItem.AdapterRAM / 1048576
If memory < 0 Then
If InStr(oItem.Name, "NVIDIA") Then
Set wssx = CreateObject("WScript.Shell")
msgbox CStr(wssx.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\000" + GPUID + "\HardwareInformation.qwMemorySize"))
End If
End If
Unfortunatelly it seems like there is no direct way of retrieving the value - within HTA itself.
I was able to get the value, however I did it using Powershell, executed the command, set its output to a specific file and read it.
Anyways, here is the actual solution I came up with specifically for this issue
wshell.Run "powershell (Get-ItemPropertyValue 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000' 'HardwareInformation.qwMemorySize') | Out-File -FilePath C:\temp\gpu_mem.txt", 0, true
Set f = fso.OpenTextFile("C:\temp\gpu_mem.txt", 1, False, -1)
gpu_mem = CStr(f.ReadAll)
With this method Im directly obtaining the integer and passing it to the VBS
Hellom, me and my friends are creating an MMORPG, and the base that we're using have this script on database.rb.
I'm doing a registration system for the website, but I need to make the server and game create files without having binary in the middle of the reading.
def self.create_account(user, pass, email)
registro = Binary_Writer.new
registro.write_string(pass)
registro.write_string(email)
registro.write_byte(Constants::GROUP_STANDARD)
# In that part, makes the save in binary.
file = File.open("Data/Accounts/#{user}.bin", mode: 'wb')
file.write(registro.to_s)
file.close
end
I tried to learn and find where i need to change to doesn't use binary, i think, that is in the part that i commented on script.
Thanks!
My problem is the same as the one mentioned in this answer. I've been trying to understand the code and this is what I learned:
It is failing in the file parse_xml.cgi, tries to get messages (return $message{$name}) from a file named messages (located in the html_en directory).
The $messages value comes from the method GetMessageHash in file adminprotocol-lib.pl:
sub GetMessageHash
{
return $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"}
}
The $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} is set in the file streamingadminserver.pl:
$ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} = $messages{"en"}
I dont know anything about Perl so I have no idea of what the problem can be, for what I saw $messages{"en"} has the correct value (if I do print($messages{"en"}{'SunStr'} I get the value "Sun")).
However, if I try to do print($ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"}{'SunStr'} I get nothing. Seems like $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} is not set
I tried this simple example and it worked fine:
$ENV{"HELLO"} = "hello";
print($ENV{"HELLO"});
and it works fine, prints "hello".
Any idea of what the problem can be?
Looks like $messages{"en"} is a HashRef: A pointer to some memory address holding a key-value-store. You could even print the associated memory address:
perl -le 'my $hashref = {}; print $hashref;'
HASH(0x1548e78)
0x1548e78 is the address, but it's only valid within the same running process. Re-run the sample command and you'll get different addresses each time.
HASH(0x1548e78) is also just a human-readable representation of the real stored value. Setting $hashref2="HASH(0x1548e78)"; won't create a real reference, just a copy of the human-readable string.
You could easily proof this theory using print $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} in both script.
Data::Dumper is typically used to show the contents of the referenced hash (memory location):
use Data::Dumper;
print Dumper($messages{"en"});
# or
print Dumper($ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"});
This will also show if the pointer/reference could be dereferenced in both scripts.
The solution for your problem is probably passing the value instead of the HashRef:
$ENV{"QTSSADMINSERVER_EN_SUN"} = $messages{"en"}->{SunStr};
Best Practice is using a -> between both keys. The " or ' quotes for the key also optional if the key is a plain word.
But passing everything through environment variables feels wrong. They might not be able to hold references on OSX (I don't know). You might want to extract the string storage to a include file and load it via require.
See http://www.perlmaven.com/ or http://learn.perl.org for more about Perl.
fix code:
$$ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} = $messages{"en"};
sub GetMessageHash
{
return $$ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"};
}
ref:
https://github.com/guangbin79/dss6.0.3-linux-patch
I am writing a script to capture the login time. In the final production, there would be no input from any user. However I am testing it and I wanted to know how I add extra code to determine that
If its in 'debug' mode AND
The user that is logging in is me (lets say my username is joe.smith on the domain called EXAMPLE)
then present an input box to allow me to type the date, time for logging in.
All other users would never see this and it would capture today with the system time.
I would also like to hide the code so if the script is opened by the wrong person, they wouldnt be able to make heads or tails of whats going on.
You can use a command line parameter as Matt says to set the script into debug mode, eg
dim isdebug: isdebug = WScript.Arguments.Named.Exists("debug")
WScript.Echo("in debug mode: " & isdebug)
Which you can invoke with
wscript debugscript.vbs /debug
To get the current user name, you can use either the WMI Service or the WScript.Network object.
Once you have the username, you can conditionally throw up an InputBox and collect the value returned:
dim date_: date_ = Now()
if isdebug and username = "me" then
dim value: value = CDate(InputBox("enter the date and time (dd/mm/yyyy hh:mm:ss)", "please", Now()))
' validate the input here
date_ = CDate(value)
end if
And finally, to obfuscate your code you could use the Scripting.Encoder although it looks like this doesn't seem to be supported on Vista or Windows 7. There does seem to be a few hits on googling the phrase obfuscating vbscript, anyway.
Most of this sounds like it can be resolved by the logic of the script.
Have a command line parameter (debug is an appropriate name) and then have some if logic in the code to do as you wish (present the input box).
For the code obfuscation, I don't know how this could be done in vbscript. Windows scripting host works with JavaScript as well though and there are plenty of tools on the web for making JS harder to read. Maybe you want to look a using JS...
HTH,
Matt
I think you can check the property App.LogMode to see if you are in 'debug' mode or not. If it is 0 then you are running debug mode and if it is 1 you are not.