Getting the last modify date of a directory in ftp - c#-4.0

How do i get when a directory was recently modify via ftp using c#
I have tried this, with no luck
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + ftpAddress + "/" + "public_html" + "/" + this.Url));
ftpRequest.Credentials = new NetworkCredential(FTPUsername, FTPPassword);
ftpRequest.Method = WebRequestMethods.Ftp.GetDateTimestamp;
DateTime FtpFileLastModified = ((FtpWebResponse)ftpRequest.GetResponse()).LastModified;
return FtpFileLastModified;

Related

Cron Job Not working with Python

I made a script :
import os , time
from pathlib import Path
from pushover import Client
client = Client("MY CLIENT KEY", api_token="MY API KEY")
###Run aquatone
###Create a directory named site if not exists
###copy urls.txt in site directory
###Check for urls in urls.txt
domains = open('/root/programming/aquarecon/domains.txt', 'r')
hue = domains.readlines()
for site in hue:
#run_aquatone = os.system('aquatone-discover -d ' + site.strip('\n') + ' -t 30')
#run_aquatone_scan = os.system('aquatone-scan -d ' + site.strip('\n') + ' -t 30 -p huge')
current_directory = os.getcwd()
url_txt_path = '/root/aquatone/' + site.strip('\n') + '/urls.txt'
#print(url_txt_path)
site_directory = Path("/root/programming/aquarecon/"+ site.strip('\n'))
time.sleep(1)
if site_directory.is_dir() == False:
print('Site Have Not Been Monitored Yet')
os.system('mkdir '+ '' + '/root/programming/aquarecon/'+site.strip('\n'))
copy_url_txt = os.system('cp '+ url_txt_path + ' ' + site.strip('\n') )
else:
print('Site Exists time to use flashback')
open_new_urls = open('/root/aquatone/' + site.strip('\n') + '/urls.txt','r')
open_old_urls = open('/root/programming/aquarecon/' +site.strip('\n') +'/urls.txt' , 'r')
readlines_old = open_old_urls.readlines()
readlines_new = open_new_urls.readlines()
client.send_message('New Subdomain Found ', title="CRON")
for i in readlines_new:
if i not in readlines_old:
client.send_message('New Subdomain Found ' + i, title="AquaRecon")
copy_url_txt = os.system('cp '+ url_txt_path + ' ' + site.strip('\n'))
and Even i set the cronjob as :
10 * * * * /usr/bin/python3.5 /root/programming/aquarecon/aquarecon.py
But the script doesn't run anytime .
For a quick info:
Aquatone is a tool to enumerate subdomains :)
Any help would be appreciated.
Thanks
I believe cron is based off of root, so when you call the pathlib, it is cron calling it, defaulting it to root.

Azure Put Blob API returns with a non-matching size of file in canonicalized Header

I am trying to upload a blob (pdf) file from my laptop to a container in Azure storage account. I found it to be working but with one glitch.
I am calculating the file size using:
f_info = os.stat(file_path)
file_size = (f_info.st_size) # returns - 19337
Then I insert this value in below canonicalized header:
ch = "PUT\n\n\n"+str(file_size)+"\n\napplication/pdf\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob" + "\nx-ms-date:" + date + "\nx-ms-version:" + version + "\n"
and send the PUT request to PUT Blob API, however, it returns an error saying, "Authentication failed because the server used below below string to calculate the signature"
\'PUT\n\n\n19497\n\napplication/pdf\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-date:[date]\nx-ms-version:[API version]
Looking at this string it obvious that authentication failed because file size which azure calculated returns a different value! I don't understand how its calculating this value of file size?!?!
FYI: If I replace 19337 with 19497 in canonicalized string and re run. It works!
Any suggestion on where I am making mistakes?
Below is the code:
storage_AccountName = '<storage account name>'
storage_ContainerName = "<container_name>"
storageKey='<key>'
fd = "C:\\<path>\\<to>\\<file_to_upload>.pdf"
URI = 'https://' + storageAccountName + '.blob.core.windows.net/<storage_ContainerName >/<blob_file_name.pdf>
version = '2017-07-29'
date = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
if os.path.isfile(fd):
file_info = os.stat(fd)
file_size = (file_info.st_size)
ch = "PUT\n\n\n"+str(file_size)+"\n\napplication/pdf\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob" + "\nx-ms-date:" + date + "\nx-ms-version:" + version + "\n"
cr = "/<storage_AccountName>/<storage_Containername>/<blob_file_name.pdf>"
canonicalizedString = ch + cr
storage_account_key = base64.b64decode(storageKey)
byte_canonicalizedString=canonicalizedString.encode('utf-8')
signature = base64.b64encode(hmac.new(key=storage_account_key, msg=byte_canonicalizedString, digestmod=hashlib.sha256).digest())
header = {
'x-ms-blob-type': "BlockBlob",
'x-ms-date': date,
'x-ms-version': version,
'Authorization': 'SharedKey ' + storageAccountName + ':' + signature.decode('utf-8'),
#'Content-Length': str(19497), # works
'Content-Length': str(file_size), # doesn't work
'Content-Type': "application/pdf"}
files = {'file': open(fd, 'rb')}
result = requests.put(url = URI, headers = header, files = files)
print (result.content)
As mentioned in the comments, the reason you're getting the content length mismatched header is because instead of uploading the file, you're uploading an object which contains file contents and that is causing the content length to increase.
Please change the following line of codes:
files = {'file': open(fd, 'rb')}
result = requests.put(url = URI, headers = header, files = files)
to something like:
data = open(fd, 'rb') as stream
result = requests.put(url = URI, headers = header, data = data)
And now you're only uploading the file contents.

Write output of replaceStream to new file

I am writing a progrma in node and using replaceStream and I want to write the out of replacestream to a file, but all I can get it to do write now is print to the console using this code:
fs.createReadStream(filePath + "/" + fileName)
.pipe(replaceStream(imagePath, newPath))
.pipe(process.stdout);
Just write it to a writable stream.
fs.createReadStream(filePath + "/" + fileName)
.pipe(replaceStream(imagePath, newPath))
.pipe(fs.createWriteStream(filePath + "/" + newFileName));

RDP to call an EXE file, not the whole desktop

I have used this code to implement RDP.
This works fine but now I want to implement a system , that will call a particular EXE file from the server. Not the whole desktop.
Any idea how can I implement this?
Process rdcProcess = new Process();
rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(#"%SystemRoot%\system32\cmdkey.exe");
rdcProcess.StartInfo.Arguments = "/generic:TERMSRV/192.168.0.16 /user:" +Saltlake1" + " /pass:" + "saltlake#1234";
rdcProcess.Start();
rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(#"%SystemRoot%\system32\mstsc.exe");
rdcProcess.StartInfo.Arguments = "/v " + "192.168.0.16";
rdcProcess.Start();

renameTo() in grails to rename an apk file to zip file

I want to upload apk files. And then convert it to zip in order to extract some information.
I used renameTo() function but its not working.
String newFilename = "new.apk"
new File(f.getOriginalFilename()).renameTo(new File("new.apk"))
(f.getOriginalFilename() will return the name of an apk file) How exactly can I do renaming?
Got it. need to give the full path to the file. for example
new File( webRootDir + "/" + [folder name] + "/" +f.originalFilename ).renameTo(
new File(webRootDir + "/" + [folder name] + "/" +appname+".zip") )
will solve the problem.
And Groovier using GStrings:
new File("$webRootDir/$folderName/${f.originalFilename}").renameTo(new File("$webRootDir/$folderName/$appname.zip"))

Resources