Friday, September 30, 2011

python RegularExpression 1

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Demonstrate how to use Regular Expression
import re
#Compile Regular Expression first.
re1 = re.compile('matchBullet')
print re1.match('matchBullet')
print re1.match('matchBullet').group()

re2 = re.compile('matchBala')
match1 = re2.match('matchBala')
print match1.group()

searchstr = "Bala"
re2=re.compile(searchstr)
match1 = re2.match(searchstr)
print match1.group()

#END

Output
bala@bala-laptop:~/python$ python RE.py
<_sre.SRE_Match object at 0x7feb846091d0>
matchBullet
matchBala
Bala
bala@bala-laptop:~/python$

Python shutil

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Demonstrate how to use file I/O high-level module
import shutil

#we will create an alias for shutil like s
s = shutil
#This would change the date and time on the file which is created
s.copy("data1","data2")
#This would not change the date and time on the file which is created
s.copy2("data1","data3")
#This would move data1 to the destination path
s.move("data2","/home/bala/data3")
#If we want to move an entire directory
src="bala"
dst="bullet"
s.copytree(src,dst)

dst="bullet1"
#The third argument if it is 0 we will copy the symbolic link file directly, if it is 1 it will just copy the symbolic link
s.copytree(src,dst,0)

dst="bullet"
s.rmtree(dst)

#END

Thursday, September 29, 2011

python functions

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Purpose: Demonstrate Function

def add(a,b):
    sum = a+b
    return sum

print "*********Demonstrating Functions***********"
a = input("Enter the first value to be added :")
b = input("Enter the second value to be added :")

addedvalue = add(a,b)

print "The sum of a : ",a," and b : ",b," is = ", addedvalue

#END
 
Output

bala@bala-laptop:~/python$ python function.py
*********Demonstrating Functions***********
Enter the first value to be added :2
Enter the second value to be added :3
The sum of a :  2  and b :  3  is =  5
bala@bala-laptop:~/python$

Forms

HTML forms

Name:
Password:

This would lead you no where


Wednesday, September 28, 2011

Non changable list

#!/usr/bin/python
lists = ["Bala","Subramaniam","Natarajan"]
print "The lists is of type : ", type(lists)
lists[2] = "changed"
print lists
tuples = ("Bala","Subramaniam","Natarajan")
print "The tuples is of type : ", type(tuples)
tuples[2] = "changed"
print tuples

Editing a log file

#!/usr/bin/python
#To print a list of numbers
import string

log_file = "20110923 10.0.0.1 1110 192.168.1.1 80 404 vaka.html"
print log_file
print "The type of log_file is : ", type(log_file)
print string.split(log_file)
log_file2 = string.split(log_file)
print "The type of log_file2 is: ", type(log_file2)
print "The date in our log file is : ", log_file2[0]
log_file3 = string.join(log_file2)
print "The type of log_file3 is : ", type(log_file3)


Friday, September 23, 2011

Python String List

#!/usr/bin/python
#To print a list of numbers
print range(11)
numlist = range(5)
print "I am printing numlist populated by range method", numlist
print "Here I am printing values starting from 1st position",range(1,5)
print "Printing values starting from 1st position i+2",range(1,11,2)
strlist1 = ['Bala','subramaniam','Natarajan']
print "I am printing the string list1", strlist1
strlist1.reverse()
print "Reversing string list1", strlist1
strlist1.reverse()
strlist2 = ['Bala','Revathi']
print "I am printing the string list2", strlist2
strlist1.append(strlist2)
print "I am printing the appended string list1", strlist1
print strlist1[3][1]
strlist1.extend(strlist2)
print "I am printing the extended string list1", strlist1



#!/usr/bin/python
#To print a log_file
import string

log_file = "20110923 10.0.0.1 1110 192.168.1.1 80 404 vaka.html"
print log_file
print "The type of log_file is : ", type(log_file)
print string.split(log_file)
log_file2 = string.split(log_file)
print "The type of log_file2 is: ", type(log_file2)
print "The date in our log file is : ", log_file2[0]
log_file3 = string.join(log_file2)
print "The type of log_file3 is : ", type(log_file3)


Thursday, September 22, 2011

Older versions of Java & PDF

http://www.oracle.com/technetwork/java/archive-139210.html

http://get.adobe.com/reader/otherversions/

Wednesday, September 21, 2011

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Date: 21-Sep-2011
#Purpose: lists

nlist = [1,2,3,4,5,6,7]
print "The value of nlist is", nlist
nlist.reverse()
print "The reversed value of nlist is", nlist
nlist.reverse()
print "The re-reversed value of nlist is", nlist

nlist2 = [8,9,10]
print "The value of nlist2 is: ", nlist2

nlist.append(nlist2)
print "The value of nlist.append(nlist2) is: ", nlist

print "The first value in nlist is: ", nlist[0]
print "The second value in nlist is: ", nlist[1]
print "The third value in nlist is: ", nlist[2]
print "The eight value in nlist is: ", nlist[7]
print "The eight value in nlist separately is: ", nlist[7][0]
print "The nineth value in nlist separately is: ", nlist[7][1]

#POP will behave similar to STACK Last In First Out
nlist.pop()
print "We poped out the last value of nlist", nlist

nlist.extend(nlist2)
print "We'v incorporated nlist2 elements in nlist", nlist
print "The eight value in nlist is: ", nlist[7]

nlist.pop()
print "We poped out the last value of nlist", nlist

#To get First In First Out we need to specify the number.
nlist.pop(0)
print "We poped out the first value of nlist", nlist

#To insert value in the nlist
nlist.insert(0,1)
print "We populate the first value of nlist", nlist

#END


Friday, September 16, 2011

Tiny HTTPD Proxy

This URL has a small http proxy.

http://www.oki-osk.jp/esc/python/proxy/

Wednesday, September 7, 2011

DigiNotars are Back, be aware

I was keeping a tab about the CA compromize of DigiNotars for a few days now and I did manually remove that CA from my Trusted list.

Today 7-Sep-2011 I tried to update my Ubuntu 10.04 it told me that there are some mozilla firefox packages to be installed so I allowed it.



Once the update was over my browser restarted and what do you know the very certificate which I chose to distrust started appearing in the trusted CA.

http://blog.mozilla.com/security/2011/08/29/fraudulent-google-com-certificate/

Got an answer at mozilla.com


https://support.mozilla.com/en-US/questions/871927#answer-242337


Sunday, September 4, 2011

PHP to unzip password protected file

You need apache2 and PHP installed on your system. The first file is index.html


 Next you need to have a file named zip.php


Wola all your encrypted files will get uploaded to the upload directory.

If needed you can comment the last 15 lines if you are just going to submit encrypted zip files.


Friday, September 2, 2011

Zip on BASH :-)

bala@bala-desktop:~/Desktop$ zip -e infected.zip 10199.exe
Enter password:
Verify password:
  adding: 10199.exe (deflated 9%)
bala@bala-desktop:~/Desktop$ md5sum 10199.exe
f469bf255c2c8fedec173cd17395ff11  10199.exe
bala@bala-desktop:~/Desktop$ md5sum infected/10199.exe
f469bf255c2c8fedec173cd17395ff11  infected/10199.exe
bala@bala-desktop:~/Desktop$