Monday, February 9, 2015

OpenCV - No such file or directory

Today was the first time I tried using openCV to perform some image processing.
But everytime I tried to load an image it kept displaying

'Error 2 : No such file or directory'

Obviously I thought it might have been a path problem, but checking it repeatedly I realized that path was correct and for some reason it wasn't reading.

Searching online, I saw many users complaining about the same error but no solutions were really given.

After toying around, I found that it could open png files but couldn't open jpeg not gif images.

So the simple work around was, opening the image with paint and saving it as a png.

I don't know why this works, but it's a quick work around.

If anyone understands why, please do leave a comment below.


Thursday, December 18, 2014

The ULTIMATE guide to extend battery life on your android phone

Today's post will be on how to extend your battery life. It will run through all the basics and advanced topics. If I missed out on anything, please do mention it below in the comments section.

Note: These are just tips that worked out for me. Everyone is entitled to his or her own opinion. Hopefully these tips would be useful to you.

Note: I'm not a big fan of battery saver apps, but there are 2 that I really enjoy. You can check them out under the advanced section (and no, its not juice defender).


THE BASICS

These tips are for those new to Android. If you're a long time user, you probably would know most of these tips. But I'll bold out the things that I think might interest even the most advanced users as well.

Let's clear up the concept of using SOT as a battery meter. This (entertaining) video from XDA developers explains why SOT shouldn't be used as a battery meter: Why shouldn't SOT be used as a battery meter

1) See what's eating your battery

Go to "Settings->Battery". Here you'll see the list of apps that are consuming your battery in a descending order. If you see something that you don't use often or you don't need, be sure to uninstall it, or go into that apps settings and see if you can somehow reduce its power consumption. (By turning off sync, etc)

Another handy tip is to go to "Settings->Apps->Running". See what apps are running. If you see an app that shouldn't be there, click on it and hit 'stop'. Less RAM consumption = More battery life.

2) AMOLED screen? Black's your favorite color. LCD screen? White's your favorite color.

This tip is for phones using AMOLED screens. The thing about about AMOLED screens is that it only lights up pixels that are colored. If a part of your screen is black, it remains unlit (or less amount of light to light them up) and less battery consumption. (AMOLED screen provide a pure black color, which look perfect on 'pure black' themes in many custom ROMS).

Now for LCD screens its better using a light theme. This is because when you use a light theme on an LCD screen, it allows you to see better and hence you can keep the brightness level on your phone to a minimum rather than having to crank it up every time when you can't see something clearly.

3) Turn off location reporting


If this option is turned on, your phone will keep on determining your location. Due to this your battery life gets depleted. If you don't need it, go to "settings->location" and switch it off. If its absolutely necessary, there are options like "Battery saving" and "Device only" to reduce the amount of battery being consumed at the expense of performance.
You can also find settings for location services for individual apps under here.

Of course if you're navigating (Eg. Google Maps) you'll need the location services in order to navigate properly.

4) Turn off other unwanted features


Other services like bluetooth, wifi, NFC etc can be turned off in your pull down notification menu. 
We all know that turning on airplane mode would be the best option to save battery life.

However its only advised to use airplane mode when you actually don't need cell phone coverage, like when you're at the gym, or an important conference (you get the idea).

A smart hack is to turn on airplane mode while charging your phone. You'll see it charge faster when compared to when your network is on.

More over, when you have WiFi use it. Using WiFi will save your battery life when compared to 2g or 3g. And a strong WiFi connection also saves more battery than connecting to a weak connection. That's because your phone tries harder to maintain that weak connection. So avoid any weak WiFi connections. The same goes with cellular coverage.

Another thing: 2g saves more battery life than 3g (I'm sure that's pretty obvious). Use 2G if all you're doing is reading up on some mail.

There's also an option : "WiFi always on during sleep". Now to turn this on or off is your decision. If you're constantly using WiFi, i'd recommend to leave this on, as it'll take more battery life every time when you're attempting to connect to a WiFi network. Otherwise, if you're a casual user you can turn this option off.

If you really need WiFi but you don't need your cell phone service, you can always turn on Airplane mode and then afterwards turn on your WiFi. You'll be able to surf the net, even though airplane mode is on.

Even when WiFi is disabled, its possible the phone could be still scanning for WiFi networks. To avoid this go to "Settings->WiFi->Advanced". Turn off "Scanning always available".

5) Turn the screen brightness down

The screen is the major source of battery consumption in Android phones. So it comes as no surprise that by turning down the screen brightness, you'll be saving a whole lot of juice.

Screen brightness is found under "Settings->Display->Brightness Level". It can also be found in your quick settings.

If you want to save battery life, don't use auto-brightness. Fact: Auto-brightness actually makes your screen brighter than what is necessary. My opinion is to choose a low brightness value and crank it up when found necessary.

6) Set your screen timeout as low as possible

There's nothing really to explain here. Go to "settings->display->sleep" and choose low timeout value. It'll set your phone to sleep if your phone has been inactive for that many seconds and save more battery.


7) Disable autorotate

This isn't really thought on when saving battery life. But by turning on autorotate, your phone's orientation sensor is constantly monitoring how you're holding your phone. This in turn will decrease your battery life. So turn it off when you don't need it.

8) Disable Google Now cards/hotword detection

The Google Now cards are actually pretty neat and to be honest I do use them. However when the cards show me how many more minutes it'll take to reach my home from the nearby bakery, its not exactly necessary. 

You can choose which cards you want to be displayed under the Google now settings. I recommend you turn off any cards that require location services because those cards would require the most amount of battery. Of course, you can decide to choose to turn off all the cards to maximize your battery life or choose another launcher.

I hardly use the 'Okay Google' function. Though it is pretty neat, its constantly monitoring for that hotword detection. My advice is to turn it off under settings, or use another launcher.


9) Turn on your power saving mode


This various from device to device. My phone is a Nexus 4 running lollipop, so there's actually a built in battery saving mode under "Settings->Battery". Reports claim that the battery saver mode on lollipop can extend your battery life for an additional 90 minutes.

However this does compromise with performance, and removes all that eye candy that lollipop offers. 

For Samsung phones, you'll find a Battery Saver mode under your settings menu.


10) Turn off (or reduce the interval period) for syncs.

Some apps like your email, will be continuously running in the background syncing information. You can reduce the interval time in which you're syncing with the service. Instead of syncing every 10 minutes, I could decide to sync my email once a day. If I'm not using my twitter account, then i'll turn off the sync for that app.

I use my phone as my primary camera. When I first got my phone, all my photos were being uploaded and backed up to my email. In turn, I used up my data plan, and my battery life was horrible. Turning off Google photo sync really saved me.

11) Don't use live wallpapers or widgets

Widgets seem to be harmless. However widgets that update your social status feed, or a simple news reader will be continuously refreshing in the background. Even live wallpapers are continuously being animated and will take their toll on the battery life. It's not so bad using the Android customization, but don't just dump every widget you have on the home screen. Use the ones that are absolutely necessary.


For notifications I like "dynamic notifcations". It'll display the notifications on your lock screen and hence you won't need to unlock your phone to view them. This feature is built into Lollipop.

12) Put your phone on silent, not vibration.

When you're in an important meeting and you're running out of juice, put your phone on silent rather than vibrate. When your phone vibrates on an incoming call or in general, it reduces the battery life of your phone. Lollipop incorporates this concept into its built in battery saver mode.

Be sure to turn off haptic feedback as well.

13) Use original batteries

Please, oh please use the official batteries made for your phone. It may cost a bit more than those cheap knock-offs, but it'll last longer and will avoid any damage to your phone.


14) Update your apps

When apps are updated, developers often introduce bug fixes or other ways to prolong your battery life. 

Again, most services like Google play will automatically inform you if there's an update available. But you'll want to make sure that 'auto-update' is off. Now the reason why I suggested this is because, we don't want a bunch of apps updating simultaneously when you least expect it. If the apps were updated using your mobile network on a long road trip, it instantly spells out death for your phone.

Most importantly, uninstall apps you don't use. These apps may be using background services and severely affect battery life.

15) Control your battery temperature


Keeping your battery temperature too hot or too cold will affect your battery. Don't allow your phone to heat up too much nor keep it too cold. Room temperature would be advised. Here are some other battery tips:

Don't completely discharge your Lithium Ion battery on your phone. If this is done often, it decreases the lifetime of your battery.

However it's advised to completely discharge your battery occasionally (After around 25-35 charge cycles) because it allows your battery to re calibrate. 

Don't leave your phone charging when its fully charged.

16) Buy a juice pack

A juice pack, is basically a cover for your phone, with a battery. This can double your battery life. However from my experience most juice packs are pretty ugly because of their size. I've seen a nexus 4 juice pack that causes the phone to be triple in size (the thickness of the phone). But hey, buying a juice pack is the best way to keep your phone alive longer.


17) Avoid ad filled apps

This one's kinda interesting. Most people don't realize it, but when you're using an ad-filled app (the free version of premium apps), the app is constantly downloading advertisements to your phone to display it to you. In addition to that, the app is probably uploading some user data to the ad provider. Best thing to do, is to go for that paid app which is ad-free.

There's a fix for this in the advanced section down below.


18) Turn off app notifications

There will always be that app, that'll be spamming you with notifications in the notification bar. To turn off that unnecessary pushing of data, go into "Settings->Apps->All apps tab" and uncheck "Show notifications". I used this on Droid VPN, when it constantly kept appearing on my notification bar displaying the upload and download rate. Things like this would affect your battery life.


19) Use ART (Android Run Time)

If you're on KitKat you have the option to use ART. This is the default run time in Android lollipop.

What ART actually does is that it compiles the app's source code when it is first installed on your phone compared to Dalvik which compiles the code every time you try to open an app. ART makes your phone much more faster, efficient and battery saving.

 To enable it in KitKat, you'll have to go to "Settings->Developer Mode" and choose the Runtime as "ART".

Your phone will restart and the whole process can take upto 10 minutes. 

And you don't really need to worry about app compatibility. Its not such a problem as before when ART was first introduced. Most apps will work on the ART now.


20) Restricting background data

You can restrict apps from upload or downloading data in the background my going to "Settings->data usage" and click on the "Restrict background data" from the menu to save a ton of battery life.

21) Turn off animation

To turn off all the animations found on android and increase your battery life go to "Settings->Developer options" and set window, transition, animator duration to off.

22) Use the right sort of charger (Fast and Slow)

Now this is kinda interesting. Different chargers will give you a different output.
There are both slow and fast types of chargers.
A slow type of charger will make your battery last longer when its unplugged but of course it'll take longer to charge. The output of this sort of charger would be around 1A.

The fast type of charger would charge your phone faster but also discharge it faster when used. A charge of this type would have around 2A as its output.

23) Avoid automated taskers

The use of apps that "kill your apps" isn't recommended. Most task managers don't know which apps are regularly used. So when you use an app to manage your running apps, if it closes an app that you use regularly it'll consume more battery life that save it. That's because the app need to start up again from scratch rather than loading it off the RAM. So please, avoid any apps that claim to manage your apps well.

Again another handy tip, there's a difference between your home button and your back button. Using the back button will remove your app from the RAM. Now on loading the app again, you'll lose much more battery life than having to load it off the RAM. The home button simply shifts your control to the home screen rather than clearing the app off the RAM. So if you're using an app often, use the home button rather than the back button to keep that app on the RAM. Once you're done with the app, use the back button or the task manager to remove the app off the RAM.



THE ADVANCED

Most of the following tips involve rooting your phone. But let's get one thing straight. Technically, rooting doesn't extend your battery life. It does however, let you customize your phone much more and based on this, you can extend you battery life. Please take a backup of your phone using recovery like CWM before attempting the following tips.


1) Greenify

Greenify has been my favorite app for many years now. I've placed this in the advanced section because of its capabilities.

In general Greenify will hibernate your battery leeching apps. It's one of the most effective battery saving apps out there.  For Rooted users, greenify will automatically hiberante your apps. If you're on non root, you'll have to do it manually (WHICH IS A PAIN).

However it does have experimental features that are worth a try. By downloading the donation package, you'll be able to hibernate system apps! Now this is one of my favorite options under greenify. However you don't want to be hibernating important apps like your alarm clock, or any service that other apps depend on, so use it wisely.

Now let's talk about xposed framework. There are many additional features for greenify if you have the xposed framework on your phone such as "keep notifications","Wakeup tracker and cutoff", "block app state abuse", etc. Greenify is most powerful when you have the xposed framework installed.

However there comes a catch. For all you lollipop users, there is no xposed framework. A lot of users, including me find xposed framework extremely useful. So it might be best to hold off on lollipop if you're heavily dependent on xposed framework and its combination with greenify. 

If you're on KitKat I highly recommend you use greenify with the donation package and xposed framework, 
If you're on Lollipop, all you can do is use the "Greenify System apps" feature, but its still worth it. Greenify definitely boosted my battery life on lollipop by a lot. 


2) Bloatware uninstall

Apps like "Root Uninstaller" will allow you to uninstall system apps. I highly recommend it if you can greenify system apps rather than actually uninstalling them as its much more safer. But if you have a phone with tons of bloatware, it can be easily uninstalled once rooted. This can increase your battery life substantially. (For me, I uninstalled the Google + app as it was annoying me way too much).

But please, take a backup of your phone before you go uninstalling system apps. You never know what may happen.


3) Break the myth: Does undervolting really save battery?

I always hear from people about undervolting their phones. I'm here to tell you that undervolting actually does save battery life, but only around 2%.

Undervolting does provide you the advantage of cooling your phone as less voltage will produce less heat.

Here's an explanation with a Nexus S:
If you leave your phone on with medium brightness, the phone would consume around 350mA (this is an average value between displaying a pure white and a pure black image).When you add the CPU usage (say around 20mA) you're consuming 370mA. Based on records, when you're undervolting to an extreme you'll be saving around 4.6mA. And this is regardless of your CPU governor. This means you'll have a total savings of 1.2%. Ouch.

Another thing about processors- usually default factory settings leave the voltage level to supply the processor with an ample amount of voltage. When the processor doesn't get the required voltage, it'll restart the phone. Now those who do try and undervolt realize this, a single reboot on your phone due to an inadequate amount of voltage reaching your processor will cause you to lose more battery on a single reboot than you undervolting your phone for the entire charge cycle.

So please, don't undervolt your phones. It's not worth it.

4) Choose the best CPU governor

To be honest, there's no best CPU governor for battery saving as all of them have different implementations. I don't really recommend a CPU governor that makes your CPU run at the lowest clock rate. You'll just get frustrated and there's no point in saving battery this way if your phone won't respond accordingly. However ondemand is a pretty good governor which can balance performance and battery life.

Here's a list:

Recommended:
1) Ondemand (Decent battery saving and performance, however the CPU can shoot up and down    rapidly which can cause a decrease in battery when compared to a stable ideal frequency).                 
2) Smartass, SmartassV2 and Smoothass (It's possible that the frequency of the CPU may go down so low that the device malfunctions. Eg. When the phone is sleeping, it might now wake up on clicking the power button)
3) The X series (Updated versions of the above governors)

Not Recommended:
1) Powersave (Your phone won't respond at all if this is on. Yes this will save the most battery, but what's the point of it if your phone won't even work properly.)



5) Remove ads from apps

I shouldn't really be teaching this. But like I said above, the free version of apps usually have advertisements which constantly upload/download data which takes their toll on battery life. There's a way though to make your app ad free. 

First you'll need root access and install "lucky patcher" apk. (The icon is a smiley face). It'll load the various apps. Just click on the app you want to remove ads from and click "open menu of patches". The click on "Remove Google advertisements". Let it do it's work and reboot your app. Next time you open your app, it should be ad free!


6) GPU throttling

For my Nexus 4, GPU throttling starts at around 39 degrees Celsius (You can see it through the thermald.config file on my nexus 4, and you'll need root access too). That means when I play a high end game, once my battery temperature reaches that many degrees, my GPU will start to throttle. Now LG/Google made this so the battery would last longer. So on your phone, if you want the battery life to last longer, you'll want to set the throttling temperature of your GPU to a lower temperature, becuase as we all know, a hot battery will reduce your battery life. However keep in mind, if the GPU throttling temperature is too low, you won't get an amazing performance while playing games/or in general. Find a GPU temperature that suits your needs. You can modify the GPU throttling temperature using any sort of custom kernel.

BUT BE WARNED. If you really don't know what you're doing you could end up messing up your phone. That's why I posted this in the advanced section.

7) Underclocking your CPU

Using a custom kernel, its possible to overclock your CPU to a high frequency rate to get the maximum performance from your android device. However for those looking to save battery, its also possible to underclock your CPU so that it runs on a lower frequency rate and hence can save your battery life to a large extent. Again you'll need root access to make these sorts of modifications.

8) Use a custom ROM

Custom ROMs usally make better usage of resources and battery life. They offer trimmed down and lighter versions of android. My personal favorites are Paranoid Android and Cyanogenmod, due to the constant updates and their developer team.

9) Turn off startup/non startup services that you aren't using.

Like windows, android has numerous startup services which you aren't probably using, Again less services running=more battery life. So using applications like System Tuner, its possible to turn off some of these services. Eg. You can turn off Google Wallet services if you aren't using it.


10) Use wakelock detector

Many people use a battery saver app when they realize their phone isn't lasting very long. I tend to avoid those kind of apps (except Greenify).

Some apps like Juice defender or the Qualcomm battery saver work well, and a majority of users use them and I'm sure they work well after seeing all the reviews online, but to be honest I've never been a big fan of battery saver apps. But I love wakelock detector.

This app is special (yes, you'll need root access). When you're finished using your phone, you'll turn off the screen. However the CPU might still be running and depleting your battery life. So what the wakelock detector app does is that, it checks which app are causing your CPU to be running after the screen is turned off. If an app is greatly using your CPU after the screen is off, you should uninstall it. We don't want apps running and utilizing the CPU when the phone is off (unless of course you want it to).

11) Turn off cores

If you're fortunate to have a multicore processor, then its advised to turn off some of the cores. I think Franco's kernel has by default 2 cores on and the kernel with Paranoid android had 1 kernel on (or was it the other way around?). Anyways, my Nexus has a quad core processor, so I generally turn off 2 cores. This can be achieved through any custom kernel. Most of the time, i'll be using my phone for email and reading so there's no point in turning on all 4 cores. However if I felt like playing a power hungry game, I could just turn on the performance CPU governor to turn on all my cores at 1.5Ghz.

12) Increasing the Read Ahead Buffer Size

This mod can be found in the Trickster mod app. Under the "General" tab, go to "Read Ahead Buffer Size" under "I/O control" and set the value to around 3MB (3072). A higher buffer size will allow better performance and save battery life. 

Important: Don't set this too high. Setting a buffer size too high will require your phone to generate a large buffer size every time which can be strenuous. Keep it around 3Mb. Its the perfect size. 


EXTRA TIP

 Turn on AC charging (Read the note at the bottom)

This tip doesn't really save battery, but it allows you to charge faster. When you plug your phone into a laptop, under battery settings it'll show up as  "Charging (USB)". This is because some of your data pins on your USB are being reserved for data transfer and not for charging. You can make those pins available for charging my enabling the "AC charging" option available on custom kernels to charge your phone much faster.

This tip will vary on the type of phone you have. I've seen it work better on some phones than others. Plus since the data pins are disabled, you wont be able to transfer media to your phone when connected to your laptop (again, this varies depending on your phone). 

If the above tip worked out for you, under "Settings->Battery" it'll appear as "Charging (AC)".


BUT this post is related to the above "Fast charger/ Slow Charger tip". Your battery will probably discharge a bit faster, so this is only meant to be used when necessary.


Sunday, November 30, 2014

Sending secret text messages as audio files

So today's post will be on how to encode a picture as a sound. The topic came up, because my seminar topic was on cryptography, so I was wondering what else could I do with it.

This will let you encrypt secret messages as audio files, so a hacker won't be able to understand there's a secret message embedded within the audio file (if somehow intercepted).
  
So there's basically two things you need.

The sending side will need a software called Coagula. This software actually lets you draw a picture with the help of a paint brush.


So this is my picture, after I drew it with Coagula. Now click "save as sound" to save the bmp file into a WAV file. 

On seeing the WAV file, it doesn't look suspicious and you can even play it using your media player and listen to it (though it sounds like a dying cat). It'll be small in size which makes it perfect for emails, etc.

Next, the receiver side will need a software called "Sonic Visualizer".
On opening the WAV file on sonic visualizer, it looks like an ordinary audio file.  


To encrypt the message, go to "layer" and add a "Spectrogram layer". You will be able to see the original encoded text.

Pretty cool, right? 

Links: 
Coagula: http://www.sonicspot.com/coagula/coagula.html
Sonic Visualizer: http://www.sonicvisualiser.org/download.html


Monday, October 13, 2014

Thoughtworks Placement

So the other day I attended the Thoughtworks placements held at KMEA college through Shreds.
If you haven't heard of Thoughtworks you should really check them out. It's a really cool company tailored for coders and enthusiasts of that field.

Let me start off by saying that, I didn't get the job. I reached till the top 12 (I think) before they kicked me out :) I later found out that Thoughtworks has one of the toughest placement processes with around 6 rounds of coding, logical test and interviews.

Despite how it sounds, the experience was amazing. Here's my brief perspective on how it went.

The process was split as two days. The first day consisted of coding and logical rounds.
If you're really good at coding, this is definitely the company you want to be working for.

The first round was a simple coding round. We had half an hour to solve 5 simple questions. The most exciting part about this was, you could use ANY language. Yes, ANY language.

The questions were something along the lines of,

1) Print numbers from 1-100 and for numbers that are divisible by 3 print "fizz" instead of the integer, divisible by 5 print "buzz" and those divisible by 3 and 5 print "fizzbuzz".

2) Implement numbers as words. Eg 123 as one two three.

3) Reverse a sentence. Eg. Hello World => World Hello

4) Enter a list of words and search for the keyword if it exists. Eg. Hello World Good Bye.
    Search for "Good" and print "True".

5) Find all palindrome prime numbers.

I solved questions 1 and 5. I got half of questions 2 and 4.
At the end of this round, they killed off a majority of the people with most people who passed solving around 2-3 questions. There was around 500 kids, and they chose around 50?

The following rounds, they killed off half of the people writing the test for that round.

So it went like
50 to 25 after the second round
and from 25 to 12 after the third round.

The second round was a logical round. You get a set of 11 logical questions in the form of a flowchart, in which you have to perform the operations specified in the chart.
I know it doesn't make sense, but just Google  "logical paper Thoughtworks" to see their sample papers.

It involves a LOT of concentration. A LOT. It's all about concentrating on the instructions, following the correctly over and over and over again. You should really try out some of the sample question papers online. It'll surely smooth up the process.

A lot of kids were studying and reading the flowchart sample papers before the 2nd round. I didn't. So it's not necessary to practice it before hand, but it does help.
I didn't really think i'd pass this round, but somehow I did :)

The third round consisted of pair coding. This was an interesting round, in which you got a question (I'm pretty sure they took it off from hackerrank.com) and then they give you one of their own developers to work with!
You were allowed to ask your Thoughtworks developer ANYTHING. Syntax errors, strategies, etc.
You just needed to code the output according to the question in the neatest and most organized way.
Sadly, I'm not super great with C++ like I am with C. So I couldn't really organize my program into classes and objects.
At the end of the day, I think it was the way I solved the problem that made me pass that round. I used a simple solution that reduced the complexity of the question, even though I didn't get 100% of the output nor was my code super "neat". But it was however, VERY SHORT.

That was the end of day 1.

For day 2, there were around 12 people remaining.
And there were 3 interviews.

So I got kicked out after the first interview.
I had two interviewers. The whole process took around maybe an hour. Mostly they ask on data structures and things on your resume.

My best advice for you is to make another resume for this round. Make it small and concise. Add the things that you know COMPLETELY on your resume, because they'll ask you every single detail of any topic on your resume.

They said I was out because my data structure skills were lacking. They gave me a problem to solve, and even though I did solve it in some ways, they weren't impressed as they were looking for a more better solution.

My second advice for this round is that REVISE AND REVISE your data structures. They want developers and if you don't know your data structures AND HOW TO APPLY THEM IN A PRACTICAL APPLICATION, they'll kick you out.

I don't know much around the second round, but it was technical so I guess it was similar to the first round.

The last round was a HR round. However i've heard that if you made it to this round, you'll definitely be a Thoughtworker by the end of the day.

Most of the 12 people who attended the interview got kicked out after the first round.

I'm proud to say that my classmate actually got the job after 3 rounds of intense interviews.
At the end they only selected 2 students out of the hundreds they came.

All I have to say is to work hard on your coding skills, learn your data structures and learn how to incorporate them efficiently. Good luck!

Saturday, October 4, 2014

Mix, match and exploit

On many sites we can see a php script, with a variable assigned to a value. Based on the value assigned to the variable, a page will load.

Example
products.php?category=1
products.php?category=2

Depending on the value 1 or 2, will a page load.


Now this may be prone to SQL injection. To check insert a ' at the end of the URL. If it IS prone, the page will load but seem disfigured.

That's how my page loaded. With a tiny missing link on the top left corner.
Now here comes the fun part. If you can find a table on the site, (which I've explained how to find in previous posts) we could view some sensitive information.
On this page, there was an "Enter your email to add your email to our mailing list". I just added a ' to cause a syntax error causing the message:
"Syntax error, could not add email to table MAIL"
Hence I found an email table on the site.

So on this page we have the table 'mail'
So lets start with UNION ALL SELECT NULL FROM MAIL, concatenate this to the end of the URL.
Most probably the page will load as shown above. This means that we haven't selected the correct amount of columns.
So lets try
UNION ALL SELECT  NULL,NULL FROM MAIL
keep incrementing the number of null values till it turns out like this
So in my case it took 4 NULL values to display something weird. Apparently it would be some value from the table. So now let's try
UNION ALL SELECT *,NULL,NULL,NULL FROM MAIL

This again, may or may not work. What we're trying to do is to find a column in which the values are in a text form. The weird icons you see are due to reading values that aren't exactly text.
 So lets rotate the value of * till we get something out of it.
UNION ALL SELECT NULL,*,NULL,NULL FROM MAIL
keep rotating the * value till you find something.
Like this.
Apparently the second column stored the email values! By using a * at the second position, we retrieved all values of the second column! Keep rotating the * around to see what other columns you can extract!

Hope this proved to be educational!



Saturday, August 23, 2014

Ways hackers can hack your website

So in this post instead of teaching you a way to hack a part of a site, I thought i'd be interesting how professional hackers could actually hack your sites. This is a post, to describe various hacks in the easiest and most simplistic way I can.

Here are a few

1) The Denial-of-Service Attack:
Ah yes, you've probably heard of this hack as it comes up in the papers all the time. But what exactly is a DOS attack? Simple. The denial of service attack makes a machine or a network's services to be down and aren't available to users.
During this time gap, hackers will use the site to their advantage or may target specific parts of the site for their own use.
One way of carrying out a DOS attack is to flood the network with a large number of packets filling up the network's bandwidth. This may cause the CPU to run out of resources, thus causing the network to go down and allow for an easy attack.

2) Injection attacks :
If you've been following my blog, you would already be familiar with this attack.
This happens due to flaws within SQL databases. This was my first method I learned in hacking when I didnt know the password to my id at college.
When it verified the password I injected ('or'1'='1) it'll validate to true, giving me access to the database.
There are several different types of injection, especially with command like UNION ALL SELECT to give you a large amount of info extracted from websites. This is the foundation for hacking.

3) Cross Site Scripting :
 Here the hacker programs malicious content (maybe in HEX to make it look less suspicious) within a link found on a forum, chat, or blog page. The unaware user clicks on this link and it runs on the browser. The attacker can easily steal information in this way or may steal a user's session. It could steal a user's cookies and send them to the hacker. Yikes!
For example the hacker could embed code within the HTML making users enter their user name and password to the hackers site. But the user must click on the suspicious link set out by the attacker first.

4) Remote code attacks:
These kind of attacks are due to small scripts or malware. Its usually found due to vulnerabilities within directories that haven't been used either on the server or client. Nothing really special here.

5) Click jacking:
I really find this hack beautiful. The attacker actually uses multiple layers of say a text box. So the unaware user might be thinking he's typing in his password into the textbox of that site, however he's actually typing in the textbox set by the hacker. This hack takes patience and careful constructions of frames, etc.

6) Cache hacks:
This one's also kind of interesting. We all know how DNS works. If you want google.com you'll use the DNS server and it'll give you the IP to where google.com is located. But what if a hacker took over a DNS server? He could easily change one of those cache values to a website that he owns. So when you hit google.com, you're actuallly being sent to an IP that the hacker has set. Real serious.

These are the main ones I know. I'll be sure to update them as I learn more.

Please rate and subscribe.




Python Script for getting an MD5 from a string

This is a small handy python script for producing the MD5 value for a string.

MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.

Now some things on website are encoded in MD5.

Suppose on clicking 'inspect element' you stumble upon the following

"GET / users / passwords / " . md5('Users') "

Now I stumbled upon this when I entered a wrong parameter into a field that required a certain type of data giving me a MYSQL error. This left the page with a major amount of the directory exposed.

But you can expose this in numerous ways. But we're getting off topic.

So now you see that I've found a password directory but the string 'Users' is encoded with Md5.

Today's blog will teach you a python script that'll let you decipher this.

Simply import the hashlib and paste in the following line

print hashlib.md5("your text here").hexdigest()

It'll then print out the required md5 value for the string that you've entered.

Simply paste the URL with /users/passwords/your md5 value
Eg. /users/passwords/7e40c181f9221f9c613adf8bb8136ea8

You'll now be able to access the directory that was previously encrypted.

If you liked this post please share and scubscribe