Loading

Tuesday, August 4, 2009

How to Capture Screenshots of your Blackberry Screen

1. Capture BlackBerry Screenshots from Command Prompt
Get the free Java Loader Commander utility from BBforums (mirror) and unzip the file to some folder on your hard drive. Now connect the BlackBerry device to your computer via the USB cable and navigate to the screen that you want to save as an image. Open the command prompt and switch to the folder that contains the extracted files. Type JL_Cmder.cmd and press enter. Just follow the simple wizard to save screenshots of your BlackBerry screen.

2. Take Screenshots with BB Screenshooter
The official RIM command line utility discussed above can be a bit intimidating for non-techies so here’s a standard GUI based application for capturing screenshots of BlackBerry. The utility is called BBScreenshooter and it lets you take captures in multiple image formats from your Windows desktop. You can even preview screenshots before shooting. To use BB Screeenshoter, first download the JavaLoader tool and unzip it to a folder. Then download the BBscreenshoter.exe file in the same folder and run. Specify the location of Java Loader utility and the application is now ready to take pictures of your BlackBerry screen.

3. Wireless Screen Captures for BlackBerry (Quick and Easy)
The downside with either of the above solutions is that they both are desktop based so you first need to connect the BlackBerry phone to the computer before taking screen captures. Now in situations where you want to grab the BlackBerry screen while you’re miles away from the computer, CaptureIt will come very handy. Open m.thetechmogul.com in your BlackBerry browser and install the CaptureIt application (mirror). This will add a "Capture It" option to your BlackBerry menu - you can select that option, wait until the vibration is over and an image of your current BlackBerry screen will get saved either in the external memory card or to the device memory. Alternatively, you can go to Home - Options - Screen Keyboard and assign a convenience key to the Capture It application. Then you’ll be able to capture screenshots with a simple click without having to use the menu option.

Monday, August 3, 2009

Convert an MP3 File to WAV Format in Linux

How do I convert an MP3 file to WAV format under Linux using a shell prompt?

There are plenty of tools that to convert an MP3 file into WAV format. I recommend mpg321 which is a free command-line mp3 player, which uses the mad audio decoding library.

Install mpg321 or mpg123

Type the following command under Debian / Ubuntu Linux, enter:
sudo apt-get install mpg321

OR
sudo apt-get install mpg123

I recommend using mpg123 as it is updated frequently.

Install mpg123 under CentOS / RHEL / Fedora Linux

Turn on rpmforge repo and type the following command:
yum install mpg123

Convert an MP3 to WAV

The -w option will convert an .mp3 file to .wav file. The syntax is:
mpg123 -w output.wav input.mp3

OR
mpg321 -w output.wav input.mp3

A Sample Shell Script Helper Function

Add the following to your ~/.bashrc startup file (tested with bash v3.x+):
mp3towav(){
 [[ $# -eq 0 ]] && { echo "mp3wav mp3file"; exit 1; }
 for i in "$@"
 do
  # create .wav file name
  local out="${i%/*}.wav"
  [[ -f "$i" ]] && { echo -n "Processing ${i}..."; mpg123 -w "${out}" "$i" &>/dev/null  && echo "done." || echo "failed."; }
 done
}

Use it as follows:
mp3towav *.mp3
mp3towav "this is a test.mp3"
ls *.wav

Linux Tune Network Stack (Buffers Size) To Increase Networking Performance


I have two servers located in two different data centers. Both servers deals with a lot of concurrent large file transfers. But network performance is very poor for large files and performance degradation take place with a large files. How do I tune TCP under Linux to solve this problem?

By default the Linux network stack is not configured for high speed large file transfer across WAN links. This is done to save memory resources. You can easily tune Linux network stack by increasing network buffers size for high-speed networks that connect server systems to handle more network packets.

The default maximum Linux TCP buffer sizes are way too small. TCP memory is calculated automatically based on system memory; you can find the actual values by typing the following commands:
$ cat /proc/sys/net/ipv4/tcp_mem

The default and maximum amount for the receive socket memory:
$ cat /proc/sys/net/core/rmem_default
$ cat /proc/sys/net/core/rmem_max


The default and maximum amount for the send socket memory:
$ cat /proc/sys/net/core/wmem_default
$ cat /proc/sys/net/core/wmem_max


The maximum amount of option memory buffers:
$ cat /proc/sys/net/core/optmem_max

Tune values

Set the max OS send buffer size (wmem) and receive buffer size (rmem) to 12 MB for queues on all protocols. In other words set the amount of memory that is allocated for each TCP socket when it is opened or created while transferring files:

WARNING! The default value of rmem_max and wmem_max is about 128 KB in most Linux distributions, which may be enough for a low-latency general purpose network environment or for apps such as DNS / Web server. However, if the latency is large, the default size might be too small. Please note that the following settings going to increase memory usage on your server.


# echo 'net.core.wmem_max=12582912' >> /etc/sysctl.conf
# echo 'net.core.rmem_max=12582912' >> /etc/sysctl.conf


You also need to set minimum size, initial size, and maximum size in bytes:
# echo 'net.ipv4.tcp_rmem= 10240 87380 12582912' >> /etc/sysctl.conf
# echo 'net.ipv4.tcp_wmem= 10240 87380 12582912' >> /etc/sysctl.conf


Turn on window scaling which can be an option to enlarge the transfer window:
# echo 'net.ipv4.tcp_window_scaling = 1' >> /etc/sysctl.conf

Enable timestamps as defined in RFC1323:
# echo 'net.ipv4.tcp_timestamps = 1' >> /etc/sysctl.conf

Enable select acknowledgments:
# echo 'net.ipv4.tcp_sack = 1' >> /etc/sysctl.conf

By default, TCP saves various connection metrics in the route cache when the connection closes, so that connections established in the near future can use these to set initial conditions. Usually, this increases overall performance, but may sometimes cause performance degradation. If set, TCP will not cache metrics on closing connections.

# echo 'net.ipv4.tcp_no_metrics_save = 1' >> /etc/sysctl.conf

Set maximum number of packets, queued on the INPUT side, when the interface receives packets faster than kernel can process them.

# echo 'net.core.netdev_max_backlog = 5000' >> /etc/sysctl.conf


Now reload the changes:

# sysctl -p


Use tcpdump to view changes for eth0:

# tcpdump -ni eth0

How do you dispose of old hard drives?

You probably have a few old hard drives sitting around collecting dust. They may not be MFM or RLL drives, but you've probably got some 8 or 20 gig drives sitting around from an old upgrade. Do you even remember what OS was on those systems, let alone what sort of sensetive information might be sitting on those drives? According to some of the latest findings out there, you better either take the time to do a military-grade wipe on the drives or physically destroy them; the alternative is throwing them out and hoping no one comes along and does a forensics analysis of your old drive in the hopes of finding your credit card information.

Deleting the files on your drive just isn't enough anymore. The tools exist for even an amateur computer sleuth to recover files on the hard drive if it wasn't properly formated. And we need these tools for the occasional mistake or disaster, but we have to be aware of the fact that the bad guys have them too. Anything you might be able to recover using testdisk or ddrescue will also be recoverable by someone snooping for account information or credit card numbers.

So here's what I do: at work I use any of the many Linux LiveCD's, as long as they contain Wipe. Three or four passes over the data with random 1's and 0's make the data pretty hard for anyone except the most talented and dedicated forensics analyst to recover any data. And at home I have even a simpler solution: a cordless drill with a 3/8" titanium bit. One or two holes in the platter make certain anyone without a scanning electron microscope isn't going to be able to use the disk in the future. And it only takes about 30 seconds per drive.

Installing Backtrack 3 to a harddrive

I started with a clean drive, so you might have to manipulate your partition tables. I’m going to assume that you’re comfortable working with partition tables. If not, work on your googleing.

Here are the steps I took to install Backtrack 3 on to my laptop harddrive.

1. Boot system from Backtrack 3 CD.
2. Once booted, open a terminal and type; cfdisk
3. Re-configure your partitions. I made several; / , /boot, /var, /tmp, /home, swap. Be sure to set your / or /boot partition to be bootable.
4. When your changes are complete, use the write option and type YES to confirm the changes.
5. Reboot, booting from the Backtrack 3 CD again.
6. When the system restarts, open a terminal and enter preform the following;
bt~# mkswap /dev/sda5
bt~# swapon /dev/sda5
This formats and enables swap space. You’ll need this later
7. Create directories needed to mount up the partitions you just created. I used the following;
bt~# mkdir -p /mnt/backtrack/{boot,home,tmp,var}
8. Now format and mount the partitions you created earlier in steps 1-4. I used the following commands;
bt~# mkfs.ext3 /dev/sda6
bt~# mount /dev/sda6 /mnt/backtrack/
bt~# mkfs.ext3 /dev/sda7
bt~# mount /dev/sda7/mnt/backtrack/var
bt~# mkfs.ext3 /dev/sda8
bt~# mount /dev/sda8 /mnt/backtrack/tmp
bt~# mkfs.ext3 /dev/sda9
bt~# mount /dev/sda9 /mnt/backtrack/home
9. Once all targets are mounted, use the following command to copy the live cd to your harddrive;
cp --preserve -R /{bin,dev,pentest,root,usr,etc,lib,opt,sbin}
10. Create additional directories
bt~# mkdir /mnt/backtrack/{mnt,proc,sys,tmp}
11. Mount up /mnt/backtrack/dev
bt~# mount --bind /dev /mnt/backtrack/dev
12. Mount slash proc!
bt~# mount -t proc proc /mnt/backtrack/proc
13. Copy our Linux Kernel into place
bt~# cp /boot/vmlinuz /mnt/backtrack/boot
14. Use choot to your new Backtrack 3 installation.
bt~# chroot /mnt/backtrack /bin/bash
15. Edit /etc/lilo.conf
bt~# nano /etc/lilo.conf
and ensure both the boot and root reflect your local installation. I used options similar to the following;
boot /dev/sda
root /dev/sda5
16. When your changes are complete, write the file and exit nano.
17. Install lilo on /dev/sda
bt~# lilo -v
18. Almost done! Edit /etc/fstab to reflect your partition layout. It should be pretty simple to copy and modify existing entries. Check and double check. If this file is wrong, your system may not boot.
19. Once done, exit your chrooted environment
bt~# exit
20. Reboot! Remove the CD from the drive. If everything has gone properly, your system should boot Backtrack 3. I had to login as root and use the startx command to start KDE.

BackTrack links

How DNS Works

This is a brief, simple tutorial on how DNS (and name resolution in general) occurs. The focus will be on Windows systems, but most of it will apply to any system. You will find that once you understand DNS you can fix A LOT of issues, regardless of the underlying OS.

Overview
Here's a picture of how DNS works, at a very high level.



www.abc.com
For this how-to, we'll use http://www.abc.com/ as our example.
First, a break down of this Fully Qualified Domain Name (FQDN). The left most name before the first period is always the host name or the name of the server. In the Windows world this host name does not have to match the server name, but usually does. In this case "www"
Everything after that is the zone the host belongs to. In this case the server's zone is "abc.com".
"ABC" is a subzone of ".COM", while ".COM" is a subzone of the root zone "."
Many times you'll hear a DNS zones called domains. A domain/zone is the "abc.com" part of any FQDN. I like to use the terminology zone instead of domain because in the Windows world, domain typically signifies Active Directory, and while AD relies heavily on DNS, I like to make the distinction between the two.
Root Zone
The root zone exists on every FQDN, but is rarely expressed. Most systems will add it in without you ever knowing that it's there.
The only times I've had to use the root zone in the FQDN are on some DNS servers (namely XO's web based DNS services) when I'm trying to alias one zone to another. Namely, the web site would try to add my zone to the end of my alias, which is bad so I placed the root zone at the end to stop that.
Early Windows 2000 servers used to have a problem with DNS because for some reason it would create a root zone "." in the list. Since the root zone was local the server would attempt to resolve from there, but the zone would be empty and name resolution would fail. Deleting that zone would resolve the issue.

Name resolution order
A Windows host will try several things to resolve any name it's given.

  1. Is it me? Do I have it in my local cache?
  2. Look in the HOSTS file: c:\windows\system32\drivers\etc
  3. DNS
  4. LMHOSTS file: c:\windows\system32\drivers\etc
  5. WINS
  6. Broadcast

You'll notice that the HOSTS file is one of the first things a Windows host will check. This is why many virus's attack that file to cause redirection to malicious web sites.

Windows Host DNS Settings
Most people put in a primary and secondary DNS server in their Windows host TCP/IP settings. There is a very commonly held misconception that if the primary server can't resolve the name then the secondary will give it a try. This is not the case.
Windows will attempt to connect to the primary server, if that fails then it will attempt to connect to the secondary. If the primary connection succeeds then Windows will totally rely on that server to make the resolution. If the server can't make the name resolution then Windows will move onto the next item in it's resolution order (LMHOSTS).

DNS Resolution
DNS goes through a similar progression when resolving a host name:

  1. Is the host in my cache?
  2. Do I have the zone in my database?
  3. Do I have a forwarder?
  4. If no forwarder, do a full lookup

Quick note about forwarders
A forwarder can be considered like a delegation of the task. If you DNS has a forwarder, it will delegate the task of doing the lookup to the server specified in its configuration. The DNS server will not attempt to resolve the name itself.

Walking through the Zones
So, DNS has never seen this host before (and stored the name in cache), it does not have the zone in it's own database and you don't have forwarders turned on. That means it has to do a full lookup.
DNS works backwards through the zone on it's way to resolving the name. First up, the root domain.
The root domain is a special domain and every DNS server has a set of static IP addresses that represent the name servers for the root zones. You can look at these settings by going to the properties of your DNS server and looking at the Root Hints tab.

Talking to the Root Servers
Your DNS server now has a place to start. It goes to a root server, from its root hints list, and asks if you know any name servers for the next zone up. For our example, that would be ".COM".
Any zone that's right under the root zone is considered a Top Level Domain, or TLD.
Since your root server has probably heard of ".COM" it will return with a list of TLD name servers.
(This is step #1 of the overview picture)

Talking to the TLD Servers
Now your server goes to one of the TLD's and asks, do you know about "ABC.COM"?
The .COM server will return a list of name servers. If you've ever done a WHOIS search, the name servers returned from this is the same list your DNS server will get.
To the right I've shown an example of the return you would get from Google.com if you tried a WHOIS search on it. The only difference is, when you DNS server asks the .COM server will actually return a list of IP addresses.
(This is step #2 of the overview picture)

Talking to ABC.COM
As you can see, we've finally landed on the name servers that should know about our host, WWW.ABC.COM.
Now your DNS server will ask one of the name servers for ABC.COM, do you know a host named WWW?
The name server will return an IP address. This name will be passed down to your Windows host and it will also be stored in the DNS servers cache, for a specified amount of time known as the Time to Live.
(This is step #3 and #4 of the overview picture)

What is TTL?
TTL: Time to live. This is a setting that tells a DNS server, as well as a DNS client, how long to keep this host/zone and IP address combination in cache.
The DNS cache is simply a list of every place that's been visited and it's IP address so the DNS server doesn't have to do a full lookup every time.
Back in ancient times (3 or 4 years ago) saving every ounce of bandwidth was very important so it was not unusual to have cache's held for long periods of time, 1-3 days. The cache does not get updated until that TTL period has expired. This is why, even to this day, that most ISP's will say you need to wait 24-72 hours before your changes will take effect. What's really happening is you're waiting for the data in the DNS cache's to expire so your new settings will be re-read.
Today, bandwidth is not much of an issue and most TTL's are set in the seconds.

DNS Propagation
DNS Propagation is a term commonly used to describe the function of waiting for the TTL to expire and having your DNS server query the zone name servers for new IP addresses. Many ISP support personnel will use this term, and I'm not convinced they know what it means!
I'm not a fan of the term because I think it has some connotation that DNS servers are secretly transferring data while we're not looking. That's called Zone Transfers!

DNS Cache
If you're in DNS on your server, you can turn on the advanced view and see your DNS cache. Hosts/zones and IP addresses are stored here for the duration of that hosts TTL settings. You can delete anything and everything in here at will, as the server will simply relook anything up if it's not in the cache.
Windows hosts also have a local cache and host/zone and IP addresses will be stored in there, also for the duration of the TTL settings.
If you're making changes to a host record and it's not resolving you may need to delete the cache on your local Windows host (IPCONFIG /FLUSHDNS from a command prompt) and delete the cache from the DNS server.

Zone Transfers
This is a little bit outside the scope of this how-to, but I felt it should be mentioned.
DNS zones can be kept on multiple servers, and the data is copied using a process called Zone Transfer. At its most basic, there are primary zones (read/write copies of the zone) and secondary zones (read only copies). Typically you would set up Zone Transfers between your DNS servers to keep data up to date between them.
With Active Directory, this process is a little different. An Active Directory Integrated zone keeps all of the data in AD, and uses the AD replication processes to keep servers up to date, so no zone transfers are necessary. Windows servers support AD integrated zones, and the more traditional zones (the database is actually a simple text file).

DNS Suffix's
A common problem for Windows administrators is multi-AD domain name resolution. Let me set it up:
Primary domain: mycompany.local (HQ) Child domain: newyork.mycompany.local
Server in HQ: hqserver1 Server in New York: nyserver2
You're at the HQ and you try to ping nyserver2 but the name doesn't resolve. How come? It's a child domain with a full trust?
Windows will always try to add your default DNS suffix to a host, so if you're at HQ you're in the mycompany.local domain, so you're suffix will be ".mycompany.local". So, when you ping nyserver2, you're actually pinging nyserver2.mycompany.local. See the problem? The server FQDN is actually nyserver2.newyork.mycompany.local.
The easiest fix is to add an additional suffix to your DNS settings: "mycompany.local and newyork.mycompany.local" (see image). Now your Windows host will first try nyserver2.mycompany.local (which will of course fail), and then nyserver2.newyork.mycompany.local (which should succeed).
Should? What do you mean should? Well, does your mycompany.local DNS server know about the newyork.mycompany.local zone? Not normally. What to do? Setup a conditional forwarder on your DNS server. Type the name of the zone you want to foward (newyork.mycompany.local) and then configure the IP address to the DNS server in that domain.
Notice the differences between zone and domain as I'm using it? Unfortunately this is probably a unique differentiation so understanding different administrators will always be a challenge.

Conclusion
There you have it, you can now consider yourself an expert in DNS -- or at the very least you'll be able to fool 90% of the people you talk to!

Linux Hosting Usage Measurement Shell Script

# Hosting Measurement Script by jim ballowe
### INSTRUCTIONS
##### CREATE DIRECTORIES
####### mkdir /root/bin
####### mkdir /root/bin/storage
##### CREATE SCRIPT
####### vi /root/bin/measure.sh
##### MAKE SCRIPT EXECUTABLE
####### chmod 744 /root/bin/measure.sh
##### Create soft links so that it runs weekly and monthly
####### ln -s /root/bin/measure.sh /etc/cron.weekly/measure.sh
####### ln -s /root/bin/measure.sh /etc/cron.monthly/measure.sh

### Define variables for naming the final backup file
DATE=`date +%Y%m%d-%H%M` # Datestamp e.g 20080109-2200
DOW=`date +%A` # Day of the week e.g. Monday
DNOW=`date +%u` # Day number of the week 1 to 7 where 1 represents Monday
DOM=`date +%d` # Date of the Month e.g. 27
M=`date +%B` # Month e.g January
W=`date +%V` # Week Number e.g 37
Y=`date +%Y`
VER=1.0 # Version Number

### TEST ECHO OF STRINGS (Uncomment for debugging)
# echo Date = "$DATE"
# echo Source = "$SOURCE"
# echo Target = "$TARGET"
# echo Age = "$AGE"

### WRITE OUTPUT TO FILE
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ > /root/bin/storage/"$DATE"_measure
echo "$HOSTNAME" MEASUREMENTS for "$M" "$DOM", "$Y" >> /root/bin/storage/"$DATE"_measure
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ >> /root/bin/storage/"$DATE"_measure
echo ==== CONTENT FULL "$HOSTNAME" ==== >> /root/bin/storage/"$DATE"_measure
du -sh /var/www/ >> /root/bin/storage/"$DATE"_measure
echo ~~~~~~~~~ Content Detail ~~~~~~~~~ >> /root/bin/storage/"$DATE"_measure
du -sh /var/www/* >> /root/bin/storage/"$DATE"_measure
echo ==== DATABASE FULL "$HOSTNAME" ==== >> /root/bin/storage/"$DATE"_measure
du -sh /var/lib/mysql/ >> /root/bin/storage/"$DATE"_measure
echo ~~~~~~~~~ Database Detail ~~~~~~~~ >> /root/bin/storage/"$DATE"_measure
du -sh /var/lib/mysql/* >> /root/bin/storage/"$DATE"_measure

Sunday, August 2, 2009

Require SSL mod_rewrite apache

Require SSL using mod_rewrite under Apache in linux

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://host.domain.tld/$1 [R,L]

Saturday, August 1, 2009

Windows SMTP Test Script

Must telnet to port 25 of the mail server first
---------------------------------------------------

ehlo test

mail from:

rcpt to:

data

subject: test via telnet

test via telnet to jim b - should create a log entry

.

Changing root password in mysql

Changing root password in mysql

http://www.cyberciti.biz/faq/mysql-change-root-password/

mysqladmin command to change root password

If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:

$ mysqladmin -u root password NEWPASSWORD

However if you want to change (or update) a root password, then you need to use following command:

$ mysqladmin -u root -p oldpassword newpass

Enter password:
Change MySQL password for other user

To change a normal user password you need to type (let us assume you would like to change password for vivek):

$ mysqladmin -u vivek -p oldpassword newpass

Changing MySQL root user password using mysql sql command

This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:

1) Login to mysql server, type following command at shell prompt:

$ mysql -u root -p

2) Use mysql database (type command at mysql> prompt):

mysql> use mysql;

3) Change password for user vivek:

mysql> update user set password=PASSWORD("NEWPASSWORD") where User='vivek';

4) Reload privileges:

mysql> flush privileges;
mysql> quit


Also, you can RECOVER mysql password here:

tep # 1 : Stop mysql service

# /etc/init.d/mysql stop
Output:

Stopping MySQL database server: mysqld.

Step # 2: Start to MySQL server w/o password:

# mysqld_safe --skip-grant-tables &
Output:

[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

Step # 3: Connect to mysql server using mysql client:

# mysql -u root
Output:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Step # 4: Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step # 5: Stop MySQL Server:

# /etc/init.d/mysql stop
Output:

Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended

[1]+ Done mysqld_safe --skip-grant-tables

Step # 6: Start MySQL server and test it

# /etc/init.d/mysql start
# mysql -u root -p