Detecting Brute Force Attacks on Linux using Graylog/Elasticsearch

I noticed one of my servers is sending more logs than the other. `sshd` was the application sending the most amount of logs in the last 24 hours.

The logs look like these:

pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=116.31.116.52 user=root

Failed password for root from 116.31.116.52 port 14281 ssh2

message repeated 2 times: [ Failed password for root from 116.31.116.52 port 14281 ssh2]

Received disconnect from 116.31.116.52 port 14281:11: [preauth]

Disconnected from 116.31.116.52 port 14281 [preauth]

PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=116.31.116.52 user=root

Since the IPs are being logged, I can know from where these are coming. Let’s generate a map.

Well well well, 5437 occurrences from China. Gotta do something. Here’s frequency of the attacks this week.

It seems to have amplified today. Looking at the logs, we can see that the were trying different passwords for the user `root`. Lemme just disable password authentication for SSH.

$ vim /etc/ssh/sshd_config

Change the line

#PasswordAuthentication yes

to

PasswordAuthentication no

$ service ssh restart

And we can see the logs are no more appearing 😉

Do you wish to analyse your server logs too? Feel free to message me on Facebook or Twitter or LinkedIn

 

IoT Series: Smart Light/Sensors in the Kitchen

The Idea

The idea is simple. When someone is the kitchen, the lights should be turned on. When their’s no one,obviously it should be turned off. Wouldn’t a simple $10 IR switch from eBay do the job?

WiFi Switch with Motion Sensor attached

“Would the lights turn on even during the day” my mom asked when I presented the system to her. “Of course not” I replied. It would have be counterproductive and non-environmental friendly then.

Everyone can start using cheap sensors and all but using them in such a way that actually makes sense is what’s the challenge.

How it works

When the motion sensor detects motion, it sends a signal to via MQTT to my main app server.

The server side application calculates whether the sun is above or below horizon — the sun doesn’t rise and set at the same time throughout the year. e.g. in summer, the sun can set around 1900 but in winter, around 1800. The application will calculate the exact time  on a daily basis so I won’ have to worry about this.

If the sun is below horizon, the kitchen light will turn on. Else the motion detected will just be ignored (but still be graphed for future use).

Is that the only benefit?

Having a IoT sensors and switches would allow be to get into the next phase of my work: Machine Learning or AI (Artifical Intelligence) as you wish to call it.

For instance, you might start by looking at the graphs for each light to find a pattern visually.

Right now, I do not have the ressources to send all the data in an Elasticsearch cluster then visualise it using Kibana. Another idea would be to mine the data with Google’s Tensorflow. Alone, it will take me some time to do it all.

Previous works on IoT

If you haven’t been following me previously, I made a system that whenever I reach in front of my house, my outside lights turn on automatically for 2 minutes — the time I reverse my car and enter my house. You may find the article here: Internet of Things (IoT) in Mauritius, lemme just do it!

 

Wanna get into the world of Home Automation too? Wanna turn on your coffee machine from your bed and more? Feel free to contact me on LinkedIn, Facebook or Twitter.

Iot Series: Internet of Things (IoT) in Mauritius!

I reach home from work when it’s already dark. I got to park my car in front of my house. I said to myself wouldn’t it be awesome if I could light up the house exterior light using my mobile phone? I bought some WiFI enabled switches from the internet and installed it. Here’s a diagram of the installation.

iotarch

‘All iz well’ except for 1 problem. Nayar’s highness has stop his car, unlock his phone, launch an app, press the LIGHT ON button, then reverse his car. Nayar is not happy!!!

So I had to make a system such that whenever Nayar reaches home, the exterior lights up automatically? Makes sense right? How did I achieve this? Simple but not so simple.

img_20160923_210617.jpg

The Wireless Switch was vendor locked in; meaning it works with their cloud service and Android/iOS app. It doesn’t give me the flexibility for I need. Had to do the following steps in order to be free:

  1. Flash an Arduino firmware (from github) to the wireless switch.
  2. Create a home automation server on a raspberry pi (which I dropped in favour of cloud hosting)
  3. Create an Android app which whenever I connect to my home WiFi, I sends the TURN ON lights on

After lots of research and development, trial and error, it finally worked 😀


Is it over? Nope. Who’s gonna turn off the lights when I enter home? Ofcourse I put a 3 minutes timer in it 😛

And the Laziest Award 2016 goes to?

Coming soon. Very soon:

  • Control garage doors (R&D stage)
  • Temperature and humidity sensors (prototype stage)
  • Get status of windows/doors status: open or closed (R&D stage)
  • Home Camera Surveillance (waiting for materials)
  • Smart TVs integration (prototype stage)
  • Solar Water Tank monitoring and control inflows (R&D stage)

Wanna get into the world of Home Automation too? Wanna turn on your coffee machine from your bed and more? Feel free to contact me on LinkedIn, Facebook or Twitter.

 

 

 

Attending Front-End Mauritius Meetup July 2016

“A reasonable coding approach to CSS and Sass”

Umar presented some of the “best practices” in the CSS universe; some of which stirred some religious debate e.g. the usage of 2 spaces vs Tabs for indentation. Yusuf, a backend PHP developer, pointed out that in the PHP community, the latter have coding standards known as PSR (PHP Standards Recommendations) which is widely accepted. CSS does not have such widely accepted standards. However attempts are being made have to formalize the standards as David mentioned. I forgot the github name of the project.

Anyways, I am of the opinion that if you are following a coding standard, try to stick to it after deciding on which standards you and your team are going to use.

Another point which I remember is to NOT use CSS #Id Selectors and it makes total sense. The reason is pretty simple to me. Good programmers write code in order to cater for most scenarios. Ids can be used only once on a page. Let’s take for example a “single post page” in a blog. You know very well that only 1 post is going to be displayed on a page

#post {
  background-color: red;
}

<body>
 <article id="post">
 </article> 
</body>

vs

.post {
  background-color: red;
}

<body>
 <article class="post" id="post-15">
 </article> 
</body>

Why you should opt for the second option is that when you have to write the front-end for search page etc, you can just use the class .post without problems as many articles can appear. But during the meetup, maybe I should be replacing the post id using -data* stuffs. Gotta read more on this.

What to remember here is, never ever use # in CSS unless working with form input as per what Sundeep said.

“Vue.js Jumpstart”

Humeira introduced us about Vue.js. I used it previously. Simply love the simplicity and the level of laziness it allows developers to have. However Vue.js is a relatively new technology and I guess it’s pretty normal for big corporations to not use it in production at the moment. As time goes by, I hope Vue.js really takes off in terms of popularity thus gaining stability.

Vue.js, to me, is awesome because it allows me to concentrate on the logic of data objects  in JavaScript and I don’t have to care about the UI views. I know it would simply update itself to reflect the state of my JavaScript object. I just love declarative type UIs.

“Le futur, c’est maintenant avec CSS4”

David explained the differences between a CSS preprocessor and CSS postprocessor. Maybe I might not have yet fully grasped the differences right now but from what I can understood, preprocessors convert .sass or .less to .css. Postprocessors take plain .css augmented with new unsupported attributes by browsers and compiles it into plain .css which are supported by most browsers. Anyways, I think this topic is too advanced for me right now.

Conclusion

13662344_1075355492543126_5851506201456332392_o
Photo stolen from David

Much more happened at the meetup but this writeup is all about what struck me personally. I’d recommend you to attend future meetups so as to be able take part in the interesting debates and be up-to-date with latest front-end techs 😉

Mounting Pendrives at Boot on Raspberry Pi (or Not)

Raspberry Pi with PendriveWell, I got a pendrive that I want to be automounted on my Raspberry Pi. Simple as hell. Do an $ lsblk command. Find the drive name. Mine was /dev/sda1.

I edited the /etc/fstab file to automount it at boot

/dev/sda1       /mnt/externaldrive      auto    defaults     0       0

Problem is that when the pendrive was not on the raspberry pi, the latter would refuse to boot properly. Even the WiFi or ethernet doesn’t work. Had to actually plug in my TV’s HDMI cable to view the boot error messages.

Some googling after, found this page: http://askubuntu.com/questions/14365/mount-an-external-drive-at-boot-time-only-if-it-is-plugged-in

Edited my /etc/fstab like this now. Notice the nofail option.

/dev/sda1 /mnt/externaldrive auto nofail,auto 0 0

Now I can boot with either a pendrive in or not. 😉