Recently in programming Category

Dowload dc3dd from HERE and to your /tmp dir or whatever dir you want. 
cd /tmp/dc3dd-6.12.2
env CFLAGS=-static

./configure
make clean
make
cd src

ls -la
(You should see a dc3dd file in green along with the object files that were created during the compiling process)
strip dc3dd (this removes the debugging information that was created during the compilation process
file ./dc3dd   - just tells you that the exe is statically linked
Below is a perl script I used to pull out all the URL and email addresses out of tcpflow results from network traffic of an infected storm bot.  The script can be run using the following:

perl stormextraction -dir /data/tcpflowresults/

Here is the script:

#!/usr/bin/perl

# simple little hack to pull URL's out of tcpflow results from captured storm data
# JD Durick <jd@labgeek.net>
# runs on a directory after you have run:  tcpflow -r <storm pcap file>, this mainly contains email header information
# email address, subjects, and html links that you are asked to visit.
# version 0.1

# format of data: (really can be anything with a URL in the file)
#----------------
#To: <sms5672@daum.net>
#Subject: Holidays are near, but u know how not to give hangover a chance
#Date: Sat, 19 Apr 2008 12:13:18 -0400
#MIME-Version: 1.0
#Content-Type: text/plain;
#        format=flowed;
#        charset="windows-1250";
#        reply-type=original
#Content-Transfer-Encoding: 7bit
#X-Priority: 3
#X-MSMail-Priority: Normal
#X-Mailer: Microsoft Outlook Express 5.50.4133.2499
#X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2499
#
#Make your housewife happy with our original blue colored-tab!is http://starfoxguide.com

#TODO
# parse even more with URI to get just unique hostnames, something like $url->host()
# DNS resolver for each of URLS
# email domain breakdown

use Getopt::Long;
use MIME::Parser;                              # for later
use Digest::MD5 qw(md5 md5_hex md5_base64);    # for later
use URI::Find;
use warnings;
use strict;
my ( $dir, $output, $fullpathname,, $file, $fsize ) = "";
my ( @dir_contents, %url, %emails ) = ();
my $counter = 0;

GetOptions(
        "dir:s"    => \$dir,
        "output:s" => \$output
);

# get all the http:// urls that are found in all the emails sent out.
if ($dir) {
        opendir( DIR, $dir ) || die("Cannot open directory !\n");

        # Get contents of directory
        @dir_contents = readdir(DIR);

        # Close the directory
        closedir(DIR);
        foreach $file (@dir_contents) {
                if ( !( ( $file eq "." ) || ( $file eq ".." ) ) ) {
                        $counter++;
                        $fullpathname = $dir . $file;
                        open( FILE, "<$fullpathname" );

                        $fsize = ( stat($fullpathname) )[7];
                        #print "[$counter]:  Processing  $fullpathname and size = $fsize\n";
                        if ( $fsize < 90000 ) {
                                while (<FILE>) {
                                        find_uris(
                                                $_,
                                                sub {
                                                        my ( $uri, $orig_uri ) = @_;
                                                        $url{$orig_uri} = 1;
                                                }
                                        );
                                }
                                close FILE;
                        }
                        else {
                                next;
                        }

                        # lets get a list of all those email addresses we see

                        getEmail($fullpathname);
                }
        }
        open( OUT, ">httpfile.txt" );
        foreach my $u ( sort keys %url ) {

                # lets get rid of those http://
                        #       $u =~ s/http\:\/\///g;
                        #       $u =~ s/https\:\/\///g;
                print OUT "$u\n";
        }
        close OUT;
}

sub getEmail {
        my $filename = shift;

        open( FILE, "<$filename" );
        while (<FILE>) {
                next if ( $_ =~ /^\s*$/ );
                if ( $_ =~ /\b([A-Za-z_%+0-9]+@[A-Z0-9a-z._]+\.[A-Za-z]{2,4})\b/ ) {
                        $emails{$1} = 1;
                }
        }
        close FILE;
        open( EMAIL, ">email.txt" );
        foreach my $email ( keys %emails ) {
                print EMAIL "$email\n";
        }
        close(OUT);
}
__END__

This is done using the INTO OUTFILE command like so.


mysql> select emp_id, emp_name from emps
into outfile 'c:/test.txt';
Query OK, 4 rows affected (0.03 sec)


This simply produces the file without any fuss, each column output as is in the table.

With SPOOL we can manipulate the file by simply formatting the output of the SQL, so if we wanted to output each column in the table with a comma delimiter we would have to concatenate the values together in the SQL to produce the required result. In MySQL there are a number of options we can use with INTO OUTFILE to change the way data is written to the file. These are FIELDS ESCAPED BY, FIELDS ENCLOSED BY, FIELDS TERMINATED BY and LINES TERMINATED BY. So if we wanted our output to be enclosed in double quotes, with comma delimiters and a new line termination for each row we would use...


SELECT emp_id, emp_name
INTO OUTFILE 'c:/result.text'
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM emps;


This would produce the following file.


"0","Barry"
"1","Paul"
"2","John"
"3","Alan"


There are of course some advantages to both, you can't for example continue to output to the same file across multiple results when using INTO OUTFILE, which you can using spool, but when using INTO OUTFILE you can concentrate on what you want selected and let MySQL deal with the formatting of the output rather than having to write it long hand when using SPOOL.

As was posted on Slashdot from some dude - I thought these were excellent reasons so I thought I would post them.....

I was an IT major and switched to CS for several reasons:
* CS is more dificult, that's why I originally chose IT! I feared the math (IT requires 2 math courses while CS was closer to 9 but all ultimately most courses had a math background. CS is more math centric but you appreciate the inner workings of the field
* IT is more high level and you never quite dwelve in deep enough to appreciate things
* A good CS major can do any job an IT major can, but an IT major can not do everything a CS major can, so don't limit yourself!
* Whether you want to do sys admin or programming CS is a good choice, you'll learn how things work and you'll be better at troubleshooting advanced concepts.
* CS teaches you the theory. It's less practical application oriented but once you understand and appreciate the theory you can easily lean anything.
- Consider: A job might require you to program in visual basic to interface with an Oracle DB. If you went in IT, they might have taught you to use VB and Oracle, so you're all set. In CS, it's unlikely you did either but you took a programming languages course and a DB theory course which enables you to learn almost any language in a day. Now consider you get asked to switch from VB to C# and a mysql db. In IT you never touched either and you don't understand the basic language concepts so its harder for you to pick up both. With CS you still have the theoretical background with enables you to pick it up in a day. The same analogy trancents multiple areas (not just programming) like networking, operating systems, etc. This also applies to those who don't get a degree and just get a bunch of certs, eventually those certs become obsolete and its harder for those without a CS degree to adapt.

The only thing IT has over CS is some basic business courses, but if you get a CS degree, getting an MBA is trivial.

About this Archive

This page is a archive of recent entries in the programming category.

Perl is the previous category.

security is the next category.

Find recent content on the main index or look in the archives to find all content.