Monday, December 19, 2011

Preventing unnecessary snmpd logging in /var/log/messages

With the default config, snmpd will fill up your /var/log/messages log with unnecessary info lines. To prevent this, you can configure snmpd to log only warning and higher level log lines. In order to do so,

1- Open the below file bia vi
vi /etc/rc.d/init.d/snmpd

2- Change this line :
OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a"

with this line
OPTIONS="-LS 0-4 d -Lf /dev/null -p /var/run/snmpd.pid -a"

3-Restart snmpd
service snmpd restart


Monday, December 5, 2011

Decrypting AES-128 CBC with Python

While developing a small script to simulate MSFT Smooth Streaming client behavior, I needed to decrypt AES-128 encrypted manifest files. This task which seemed to be complex at first, turned out to be rather easy. Below is the sample code, to use with Python 2.6.5




from Crypto.Cipher import AES


#make iv a 16 bytes  byte array
toStr = lambda x: "".join([chr(int(x[i:i+2])) for i in range(0,len(x),2)])
iv = toStr(myDic["iv"])


#"key" is the 16 bytes decryption key that you got from your key server.

decryptor = AES.new(key, AES.MODE_CBC, iv)
decrypted_manifest = decryptor.decrypt(encrypted_manifest)


Friday, September 9, 2011

Creating custom commands

When using CLI of linux based OS', some regular commands that we perform everyday, even multiple times everyday, becomes a burden to type again and again. Luckily we have a simple way to ease up small stuff like that.

Let's assume that we're doing some work on our web site that has database interaction, and each time we change a configuration setting we need to restart the httpd and db services.


#service httpd restart
#service postgresql-9.0 restart

Typing 6 words every time. I am too lazy for that kind of stuff. Instead I created a new alias in the .bashrc file in my home folder. if you have a look at your profiles .bashrc file, you'll most likely see other aliases already configured by default. So just add another line, and log off/on or source that file.

#cd /root
#vi .bashrc


....

alias mv='mv -i'
alias rm='rm -i'
alias mycustomcommand='service httpd restart; service postgresql-9.0 restart'
.....

#source .bashrc

This simple tweak will definitely come in handy.