Compiling Vowpal Wabbit on Centos


Vowpal Wabbit is an awesome machine learning tool using which you can build logistic regression models online. While building it on a Centos flavor of Linux, I ran in to a lot of issues, and I wanted to highlight the steps needed to be able to build it successfully on Ubuntu. The documentation of Vowpal Wabbit includes great instructions on how to get it installed on Debian Linux but not so much for Centos:

  • If you don’t have boost libraries installed, then on Ubuntu, you need to get them via “yum install boost-devel” and “yum install boost”.
  • Then in the vowpal wabbit directory, run “./configure”
  • run “make”
  • run “make intall”
  • If you see errors like “undefined reference to pthread_create” while doing “make”, then add the following line to your configure.ac file: LDFLAGS='-lpthread'
  • That’s it!
Good luck building your machine learning models using Vowpal Wabbit.
Posted in Uncategorized | Tagged , , , | Leave a comment

2012 in review


The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

The new Boeing 787 Dreamliner can carry about 250 passengers. This blog was viewed about 1,500 times in 2012. If it were a Dreamliner, it would take about 6 trips to carry that many people.

Click here to see the complete report.

Posted in Uncategorized | Leave a comment

Android network connectivity fallback


Didn’t realize that Android only has one network connection active at any given time. So if you keep your WiFi turned on all the time, and for some reason, your WiFi connection is spotty, then Android may not really fall back to 3G. For instance, my WiFi connection at a hotel during my recent trip to Hawaii, was renewed every day. And this hotel WiFi managing system would essentially redirect all HTTP requests to its own portal to ask users to login. Now note that my WiFi connection was good – Android’s network utilities showed WiFi as available as well as connected – and hence, majority of the apps on my phone remained unable to even fallback to 3G given that HTTP requests over WiFi were really failing. 

Posted in Uncategorized | Tagged , , , , | Leave a comment

Android App Gotchas that trip you up


So I’ve decided to keep a growing list of Android gotchas that have killed my time & patience unnecessarily. Hope someone reading this can avoid these.

  • Broadcast Receiver: So if you want to use Broadcast Receiver to receive your alarms and then in the onReceive you want to do some work, e.g. save some stuff over in SharedPreferences. Good luck with that. 3 days and I have had no luck. My SharedPreferences just don’t get updated. Tried to do this inside onReceive completely. I didn’t want to start a new Service, since that would require getting a WakeLock. And if you already have an app in the store, then setting a Wake Lock will require getting users to manually grant you that permission; which means that the app can’t really be updated automatically.
  • If you add or even remove permissions from your app, then Google would mark the app to be upgraded manually, ie forget about automatic upgrades from your users.
  • Google Play store seems to schedule upgrades at midnight. So if you push a new update to your app that’s already in the store, new users will get the new version, but the older versions may have to wait almost 1 day to be upgraded.
  • An app once declared free, remains free for its lifetime, ie by Google Play Store’s ToS, you can’t convert it to a paid app later.
Posted in Uncategorized | Tagged , , , , , , , , | Leave a comment

Android – How to disable softkeyboard in an EditText box while still have the flashing cursor


Android has a pretty unfriendly design where the soft keyboard appears in any editable EditText of an activity as soon as you enter that activity. I wanted a design such that the cursor inside the textbox is still flashing, however, I didn’t want the soft keyboard (which in my opinion, hides the entire UI, making it ugly). Moreover, the user should be the one deciding whether to enter something in the textbox and not the software.

Well, to achieve this, required a combination of a hack (courtesy: StackOverflow, and StackOverflow) as well as some meddling around:

In onCreate() of the activity where you have the edittext box:

protected void onCreate(Bundle savedInstanceState) {

mAmountText = (EditText) findViewById(R.id.amount);

// This will disable the Soft Keyboard from appearing by default
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

// Provide focus to the Amount box (since it is the top edittext box inside RelativeLayout)
mAmountText.requestFocus();

}

In your layout file (call it note_edit.xml):

<?xml version=”1.0″ encoding=”utf-8″?>

<RelativeLayout
android:id=”@+id/main_layout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#ffffffff”
android:descendantFocusability=”beforeDescendants”
android:focusableInTouchMode=”true”
>

<EditText
android:id=”@+id/amount”
android:textColor=”#ff0066ff”
android:numeric=”decimal”
android:gravity=”left”
android:hint=”$0.00″
android:textSize=”48sp”
android:layout_height=”72dp”
android:layout_width=”fill_parent”
android:windowSoftInputMode=”stateHidden”
>
</EditText>

</RelativeLayout>

Posted in Uncategorized | Leave a comment

Installing Centos VMware image on Windows using Player 2.5


Ok, I had a much nicer experience installing Centos 5 image using VMware player 2.0.5 a year ago than I have had using VMware player 2.5. What a nightmare. No wonder why *nix systems and alike have been relegated to only the geek world. Who has patience to sit down for for multiple hours trying to figure out how to install a software, all that time while waiting impatiently to get over that cliff on to the things more interesting.

I will recreate the steps for everyone who wants to install Centos or another unix image on their windows host.

First, note that you can not load an ISO from VMware player at all as it only loads a virtual image in the VMX format. Moreover, since VMware player is free software, it doesn’t allow anyone to create a virtual image from ISO to VMDX either. So the only alternative is to build your own VMX. Follow the instructions in this great post here: http://www.ffnn.nl/pages/articles/linux/vmware-player-image-creation.php

In summary, the steps as outlined in the blog above ask you to (1) first create a VMware SCSI hard disk image (.vmdk format), which you can download from the same site; (2) then download an example vmx configuration file which you then edit to provide pointer to the hard disk image as well as pointer to the Linux ISO image that you want to install; (3) then you finally open the vmx config file using player; (4) Finally, as you go through the installation process, you may be asked to provide location of additional ISO images, e.g. if you only provided location of first 1 of 7 image, then you will be asked to provide location of 2 of 7, 3 of 7 and so on. I have the entire vmx config file below:

#!/usr/bin/vmware
.encoding = “windows-1252”
displayName = “Linux 2.6.x Host”
guestOS = “other26xlinux”

memsize = “512”
scsi0:0.fileName = “10G.vmdk”
ide1:0.fileName = “CentOS-5.5-i386-bin-1of7.iso”

# DEFAULT SETTINGS UNDER THIS LINE
config.version = “8”
virtualHW.version = “4”

MemAllowAutoScaleDown = “FALSE”
MemTrimRate = “-1”

uuid.location = “56 4d e4 3b 5a 83 d1 a9-fe 71 f0 c2 4e 20 b0 7e”
uuid.bios = “56 4d e4 3b 5a 83 d1 a9-fe 71 f0 c2 4e 20 b0 7e”

uuid.action = “create”
checkpoint.vmState = “”

ethernet0.present = “TRUE”
ethernet0.connectionType = “nat”
ethernet0.addressType = “generated”
ethernet0.generatedAddress = “00:0c:29:20:b0:7e”
ethernet0.generatedAddressOffset = “0”

usb.present = “TRUE”
sound.present = “FALSE”

scsi0.present = “TRUE”
scsi0.virtualdev = “lsilogic”
scsi0:0.present = “TRUE”
scsi0:0.deviceType = “disk”
scsi0:0.mode = “persistent”
scsi0:0.redo = “”
scsi0:0.writeThrough = “FALSE”
scsi0:0.startConnected = “FALSE”

scsi0:1.present = “FALSE”
floppy0.present = “FALSE”
ide0:0.present = “FALSE”
ide0:1.present = “FALSE”
ide1:1.present = “FALSE”

ide1:0.present = “TRUE”
ide1:0.deviceType = “cdrom-image”
ide1:0.autodetect = “FALSE”
ide1:0.startConnected = “TRUE”

extendedConfigFile = “template.vmxf”

virtualHW.productCompatibility = “hosted”
tools.upgrade.policy = “manual”

vmotion.checkpointFBSize = “16777216”

tools.syncTime = “FALSE”

isolation.tools.hgfs.disable = “FALSE”
usb.autoConnect.device0 = “path:1/4/6 autoclean:1”

Note that VMware player 2.0.5 used to come bundled with VMware Tools while they stripped it out of player 2.5. And of course, there is no documentation about this. The only thing I could find is some information on installing Operating System specific Packages (OSP) for ESX server. The only other information I found is by some folks who suggest installing the VMware player 2.0 and extracting the VMware Tools ISO from it, and then using it with the player 2.5. However, this is a catch 22, as you can not really install player 2.0 if you already have 2.5 installed. If anyone finds a solution for this let me know in the comments section.

Next, I wanted to make a linux version that is bootable via USB. Centos has instructions on how to achieve this. https://www.centos.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=28211&forum=37

Most of the steps there worked for me, except that it is important to reboot the VMware linux guest after you have formatted the USB drive.

Posted in Linux, Uncategorized | Tagged , , , , | Leave a comment

Can we still turn on Egypt’s Internet access?


Purportedly, Egyptian government seems to have implemented a Kill Switch on their citizens’ internet access at 12:30 am local time on Jan 27th.

This was done at multiple levels (DNS, BGP, firewalling) in order to ensure that demonstrators and protesters are unable to communicate with each other inside Egypt as well as with others outside Egypt.

1) Domain resolution: DNS servers used by Egyptian ISPs were brought down, so users can not resolve domain names and convert them to IP-addresses.

2) Inter-domain routing: Egyptian ISPs were instructed to withdraw all the BGP routes that they advertise to the rest of the Internet, so now ISPs outside Egypt have no way of reaching Egypian ISPs’ IP-addresses. So even those users who are able to resolve domain names to IP-addresses or those who are using a server’s IP-address to directly connect to the server, would be thwarted by the lack of routing. More details on this here. There are reports that at least one of the Tier-1 ISPs in Egypt, namely Noor is still announcing BGP routes.

3) Application layer filtering: At the same time, they seem to be filtering out all traffic headed from within Egypt to social networks such as Facebook, Twitter, etc. So this takes care of cases where even if someone was able to connect to Facebook’s IP-address directly and by some miracle had routing enabled between his ISP and the rest of the Internet, the connection would be filtered at the application level!!

So how can someone inside Egypt still access the Internet? Or for that matter, how can citizens of any country rally around and forge together a solution to access the Internet when their government shuts it down?

The Most likely solution revolves around some form of a peer-to-peer internet routing, and likely involves using the anonymizing ToR routing in some fashion. However, would that really work?

Suppose users inside Egypt set up ToR routers on their machines, and when they have to post messages on Facebook or Twitter, they route their connections through other ToR routers – so their IP packets will always have as destination the IP-address of another ToR router and not necessarily Facebook or Twitter. However, these packets will need at least one network link to be working, one which connects Egypt to the rest of the Internet (in this case that will have to be Noor).  But can this still work?

Most likely not. At best it will be a best-effort service, one prone to lots of long latencies and TCP resets. The reason being that currently onion routing is not optimized to look for the best route out of a country. In other words, a lot of IP packets will get lost because they may not even know how to reach Noor.

Clearly, what is needed is a disruption tolerant routing at the application layer, so that ToR routers (which essentially make an application layer overlay on top of actual IP routing) should be able to obtain information from IP routing layer and figure out quickly that there is only one way out of the country.

Posted in Uncategorized | Leave a comment

Holiday Trojans and Botnets to be aware of: Storm 3.0 and First Android Botnet


Every year around the holiday season, the malware writers and botnet operators get busy, attempting to infect new machines and recruit more unsuspecting user machines.

This year, so far there have been two interesting events:

– Mobile security company, Lookout discovered a malware namely Geinimi, that gets downloaded to your Android smartphone if you use an unofficial marketplace (currently Chinese app marketplaces) to download games such as Monkey Jump 2, Sex Positions, President vs. Aliens, City Defense and Baseball Superstars 2010. This malware or trojan then attempts to connect to several domain names such as http://www.widifu.com, http://www.udaore.com, http://www.frijd.com, http://www.islpast.com and http://www.piajesj.com to upload users’ private information including fine-grained location, device identifiers, etc.

While no one has seen the affected Android devices receiving commands from the Command-and-Control server yet, however, I strongly suspect that within the near future, we will begin seeing the first Android phone botnet. With smartphone based advertisements and location based advertising becoming ever popular, the first goal could be a new form of click fraud, where these Android devices get recruited to click on adverts. More details at Lookout’s blog.

– Storm botnet’s version 3.0 is out. It is spreading via e-mails like the earlier versions of Storm. Affected users are then prompted to download a fake flash player at which point malware gets installed on their machines. Thereafter, these new bot machines connect to domain names whose hosting IP-address is constantly being changed via IP fast-flux. Nothing new here, as we have seen all the common exploit mechanisms. But users must be careful not to be tempted to click on any suspicious emails and most importantly, be tricked in to installing fake flash players. More details at Shadowserver’s blog.

Stay safe, and enjoy the holidays!

Posted in botnets, Uncategorized | Leave a comment

Skype supernode oscillation raises questions


Skype may have built a scalable network, however, they still have their work cut out for adding fault-tolerance, resilience and security in their infrastructure as their most recent outage over Christmas eve shows. This was their first outage in the last three years, and unluckily for them, came on heels of a planned IPO, and I am sure their brand identity took some hit.

The event is a classic example of all that can go wrong by relying on user machines while building a critical piece of your infrastructure (in their case, Supernodes). Hopefully, Skype and other services will realize that they are increasingly becoming similar to ISPs and hence must incorporate network monitoring and security solutions in to their infrastructure.

The following article from Skype provides a detailed analysis of what went wrong. It is very much like dominoes falling over each other. First, a few Skype servers got overloaded which led to some Skype client versions hanging while waiting for the server to reply and thereby crashing. This further led to the Skype clients rebooting and then attempting to connect to supernodes, all at once, whereby the supernodes themselves got overloaded and crashed. Then the user clients attempted to switch back to alternate supernodes which also consequently crashed.

Can attackers bring down Skype via DDoS?

This incident shows an Achilles heel in Skype’s infrastructure that could be taken advantage of by a clever adversary. While the current outage was a classic case of “flash crowd” effect, all flash crowds can be converted in to a DDoS attack by a clever adversary. For instance, an adversary only has to make sure he overloads a set of supernodes by figuring out which users’ machines are supernodes and sending them a traffic deluge. Given that Skype does not currently have systems in place to prevent from such route flapping (or hysteresis effects), this will easily lead to users being switched to other supernodes, which in turn will be brought down by  the traffic deluge.

What could Skype have done to prevent this outage and the future ones?

Network monitoring:

Clearly, Skype needed an analytics and measurement system in place yesterday. This can be as simple as having a monitoring daemon that gathers “anonymized” statistics about CPU, network, and memory utilization on each Skype client and more importantly, at each client that has been elevated to supernode status. Then these statistics should be aggregated hierarchically, in fact by using the same overlay network that Skype uses to route calls (called Global Index). Given that such statistical information is only used for health monitoring, it is possible to save on network bandwidth by aggregating the statistics in a lossy manner, e.g. by using Bloom filters. Finally, the statistics should be aggregated at a central server or database where time-series forecasting techniques can be used to measure whether the aggregate CPU, network or memory utilization of Skype’s infrastructure is normal or above normal. Indeed, such a system if it were in place, would have alerted Skype in advance of the problems to befall their network.

Figure 1: BGP route flapping

Learning from BGP route-dampening:

Skype’s supernode oscillations are evocative of another oscillation issue that networking industry has dealt with in the past, BGP route flapping, route oscillations and route convergence. BGP  or Border Gateway Protocol is Internet’s premier inter-domain routing protocol and when a router decides to prefer one route over another, it should not do so without considering the global implications of its decision. For instance, in Figure 1 below, suppose router R2 advertises to the rest of the Internet that the best way to reach it is via router R3.  Now imagine that during an increased traffic onslaught, the link between R2 and R3 goes down due to heart-beat failures in the TCP channel established between the two routers. At that time, R3 may be tempted to advertise R1 as the best router to reach it (R3), however, that would simply mean that the traffic deluge will be shifted from the link R2-R3 to R1-R3. After some time, it is highly likely that this link R1-R3 also goes down and then R3 switches back to router R2. As you can imagine, this see-saw can keep going ad-infinitum and that’s why techniques like “route flap dampening” were invented. Luckily for Skype, there is a vast literature on route flap dampening and oscillation prevention that they can learn from.

Posted in DDoS, Flash crowds, network monitoring, Uncategorized | Tagged , , , , , , | Leave a comment

Application-layer DDoS claims its latest victims: Wikileaks, Mastercard and Visa.


Application-layer DDoS claims its latest victims: Wikileaks, Mastercard and Visa. What can the security community do to stop application-layer DDoS attacks and the ensuing nuisance for legitimate users of a web site, once and for all?

In the latest episode in the saga of WikiLeaks inspired cyber war, the websites of Mastercard and Visa were brought down by an application-layer DDoS attack. You can find more details on how the attack was launched here and here.

I didn’t find it surprising how easy it was for someone to bring these sites down with less than 1000 user machines who volunteered to be bots. What I did find surprising was that corporations such as Mastercard and Visa do not have sufficient capacity or safeguards in place to protect themselves from such an attack. Even more surprising is that we have know about application-layer DDoS attacks for almost a decade and still we hear about how such and such corporation was brought down. The first incident of application layer DDoS attack was CyberSlam operation when a TiVo vendor DDoS’ed his competitor’s site. More recently, in 2008, CNN.com was brought down by “hacktivists” allegedly from China – all they had to do was to keep their browser open with an iframe that would constantly referesh cnn.com.

Even more surprising is how corporations, enterprise networks and ISPs still don’t have an automated approach to detect DDoS attacks and prevent them automatically. Every time a DDoS attack occurs, we read about how IT folks from that web site had to quickly change their DNS provider or move to a cloud based service such as Amazon, etc. What we really need is an automated approach to handling DDoS.

I wrote my PhD dissertation half-a-decade ago and two ACM papers (INFOCOM’06, ToN’08) on this topic: on how to automatically detect DDoS attackers and then throttle them at a reverse proxy server that sits before the web server tier.

In a nutshell, my thesis talks about the various possible ways by which someone can launch an application-layer DDoS attack. An attacker can either (1) send a lot of requests too fast, or (2)  launch an asymmetric attack by figuring out the heaviest page or largest image file and fetch it many more times than other pages, (3) or a personal favorite and nastiest to detect approach, which I named “guerilla attack”, open a lot of new HTTP/1.1 sessions, send one request per session and disappear without waiting for the response from the server, i.e. keep the session with apache server half-open. Performance tests against a benchmark site showed how much damage such attacks can cause: a site which say normally serves 100 concurrent users at a time while providing them responses within 0.1 seconds can easily see the response times of legitimate users rise to 40 seconds (at which point they will be annoyed and leave the site) with the most potent attack that only involved using 300 clients generating guerilla attacks.

On the detection front, I proposed an approach to assign suspicion scores to each HTTP/1.1 session on the basis of how well behaved it is. So a misbehaving session which is either sending requests faster than normal or generating request distributions that vary from normal user browsing profiles, will be assigned a high suspicion score. Then a reverse proxy server that keeps track of CPU loads and network utilization in the web cluster will schedule sessions inside on the basis of incoming sessions’ suspicion score. So if you have a low suspicion score, your session’s requests will be given higher priority than someone with a high suspicion.

Every time I read about a new application-level DDoS, I am inspired to open source my reverse proxy code. Any of you reading this interested in helping out, just holler.

Posted in DDoS, Uncategorized | Tagged , , , , , | 2 Comments