Tag: file

Java

Check if file or directory exists in Java

Check if file exists: File f = new File("/path/to/filename"); if(f.exists()){ .. }File f = new File("/path/to/filename"); if(f.exists()){ .. } Check if directory exists: File f = new File("/path/to/folder/"); if(f.exists() && f.isDirectory()){ .. }File f = new File("/path/to/folder/"); if(f.exists() && f.isDirectory()){ .. }

Linux

Extract all printable characters from binary files

Strings is a very useful command that can extract all printable characters from binary files. Example: strings /usr/sbin/visudo | morestrings /usr/sbin/visudo | more /lib64/ld-linux-x86-64.so.2 __gmon_start__ libc.so.6 __printf_chk setgrent fnmatch readdir execv _IO_putc setlocale fopen strsignal strncmp optind strrchr __progname dcgettext getpwuid closedir getgrgid getdomainname fork futimes –More–/lib64/ld-linux-x86-64.so.2 __gmon_start__ libc.so.6 __printf_chk setgrent fnmatch readdir execv _IO_putc …

Brute-force, Enumeration, Network, Tools

Brute force directories and files names on web application

OWASP DirBuster is a multi threaded java application designed to brute force directories and files names on web application servers. DirBuster will attempt to find hidden pages and directories with a web application. Comes with a total of 9 different lists and it is extremely effective at finding hidden files and directories. It also has …

Python

Download file from url with python

We are going to use urllib. #!/usr/bin/env python   import urllib   url = "http://server.com/files/myfile.jpg" file = urllib.urlopen(url) image = open(url.split(’/’)[-1], ‘w’) image.write(file.read()) file.close() image.close()#!/usr/bin/env python import urllib url = "http://server.com/files/myfile.jpg" file = urllib.urlopen(url) image = open(url.split(‘/’)[-1], ‘w’) image.write(file.read()) file.close() image.close()

Python

Write XML to File with Python

The code #!/usr/bin/env python   from lxml import etree as ET   root = ET.Element(’data’) person = ET.SubElement(root, ‘person’) firstname = ET.SubElement(person, ‘firstname’) firstname.text = ‘George’ lastname = ET.SubElement(person, ‘lastname’) lastname.text = ‘Karpouzas’ tree = ET.ElementTree(root) tree.write(’output.xml’, pretty_print=True, xml_declaration=True)#!/usr/bin/env python from lxml import etree as ET root = ET.Element(‘data’) person = ET.SubElement(root, ‘person’) firstname = …