Amazon EC2 Port Scanning Troubleshoot

Earlier this week, I got email from Amazon EC2 Abuse Team that my instance is reported that it has been port scanning remote hosts on the Internet. Oh yeah, that’s why my instance is terribly slow a few days back. I immediately login to the instance using ssh. When I run “uptime“, load average is TOO high for my normal instance usage! Well, I googled about it. This article helps a lot to me. I resolved the issue and reply my email back to EC2 Abuse Team, detailing all my action taken. And they investigated and marked the issue as resolved in next day. :)
Here is the action I’d taken in case I forget them in future and need to ref back here.

1) ssh to my instance.
2) run lsof -i to list all my instance internet activities
3) Found lot of .sshdd activities to several IP addresses.
4) run “top” or “htop” and see .sshdd running.
5) Kill all these activities with kill -9
6) login to aws.amazon
7) edit my security group to restrict ssh inbound and allow only to my IP address.

My biggest mistake in here is that I allow ssh inbound to all IP address!(Which is not recommended by Amazon anyway and it was my carelessness). Now I have a mental note that I must not allow all IP address (0.0.0.0) to ssh inbound!!

Changing Amazon AMI MOTD

Ever wonder how EC2 logo appear when you login ssh? Want to change/add logo to be appear to ssh login user? This maybe old and can find in other blogs. Anyway, here is how to do it in Amazon AMI.

When you list the directory /etc/update-motd.d, you will see

30-banner (where EC2 logo stored)
70-available-updates
75-system-updates

If you want to change just logo, edit 30-banner only, of course with root user. If you want additional script to run, add new file, such as 80-stats, where you can define sh command. Below is example :

#!/bin/sh
uptime
echo "-----"
df -h

If you are adding new file, don’t forget to give executable permission to new file, for example, run chmod +x /etc/update-motd.d/10-newfiles. After all that, you need to run /usr/sbin/update-motd to take affect of your changes.

Are you thinking of numbers at the start of file name, like 30, 70, 75? It is display sequences. In this example, 30 will display first and then followed by 70 and 75. So you can arrange your message order this way.

By the way MOTD stands ofr message of the day!

IOKit not found Error on XCode Version Upgrade (5.1) (SDK7.1)

Today when I was archiving my iOS app, I got Apple Mach-O -Liner error.

ld: framework not found IOKit
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But I can build and run on simulators with no problem. I realized I update my XCode to latested version yesterday. The problem is the same is this link except my XCode version is 5.1 and SDK is 7.1. I followed the suggestions in that link and most other link I found in google and still I cannot fixed the problem. I still got error on IOKit framework not found.

Finally, thanks to my luck and above link, I can solve that problem successfully. Below is the steps I followed.
0) Copy IOKit.framework from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/Frameworks/
to any locations (actually this steps is optional)
1) Click on “+” in Linked Frameworks and Libraries in XCode
2) Click on “Add Other…”
3) Locate IOKit.framework and then hightlight on it (View mode should be on third mode as in picture)
Screenshot 2014-03-27 15.32.38

4) Then select Version and then select A
5) Finally, select IOKit and then press “Open”.

IOKit is added to your project!! Finally, I can build and archive successfully! :)

UIScrollView Zooming Glitches…

The other days, I have been implementing app for my company. One of the parts of the app is image zooming. I am using UIScrollView and UIImageView for this.

- (void) viewDidLoad
{
   [super viewDidLoad];
   self.myScrollView.minimumZoomScale = 1.0;
   self.myScrollView.maximumZoomScale = 5.0;
   self.myScrollView.contentSize = CGSizeMake(939, 704);
   self.myScrollView.delegate = self;
}

- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
   return self.myImageView;
}

But when I tested with actual device which is on iOS 6, I found out that zooming caused so much glitches and after zooming, picture is also out of position. Again I tested the same app on device with iOS 7, there is no glitches. It’s so wired, isn’t it!

Googling pointed me to this. Although actual answer was not helping, comments on answer did help me!

It was because I was using Autolayout in Storyboard! When I un-ticked “Use Autolayout” from my View in storyboard, it’s working fine in both iOS 6 and 7 now!
Of course, I have to do all the alignment on views again to work on both iOS 6 and 7.

It’s just a small things but I felt like “phew!”. :)

BIRT and Tomcat Timezone

Today, I found a problem in our report which is using BIRT. The problem is that all the datetime are using GMT time. As usual, I searched on Mr. Google and found a lot of answers such as:

  • “passing __timezone in viewer” (No, I can’t pass __timezone because I am using API rather than viewer)
  • “Set Locale”.

None of these works for me. I checked my server date and it shows correctly with GMT+8. I have already set PHP timezone also. Still when I run report, datetime is shown with GMT.

Then, I remembered that I am using Tomcat7 to show my BIRT report. But I don’t see any catalina.sh or .bashrc file in my server to edit for timezone. But then I remembered one config file (tomcat7.conf) which is located in /usr/share/tomcat7/ folder and when I VI into it, I found JAVA_OPTS there. I enable JAVA_OPTS and add “-Duser.timezone=Asia/Singapore” to it so that it looks like

JAVA_OPTS="-Duser.timezone=Asia/Singapore"

and then restart tomcat. Then my date in report shows correctly!

I am not very sure it is a healthy way to edit tomcat7.conf file but at least it works for me. :)

USB Recovery Using Clonezilla Live

It’s a long process for me to figure out “How to make USB Recovery using Clonezill Live” even if there is plenty of documentation and tutorial on internet. So I made this post people like me to create simple USB Recovery. Simple USB Recovery means plug in USB in target machine, boot from USB, press “Enter”, press “Y” twice and reboot. That’s it! So here is it.

Step 0: Preparation

Need 2 USB Disks. Let’s say USB1 and USB2. USB1 for Clonezilla Live Boot and USB2 for USB Recovery Disk.
Make sure both USB1 and UBS2 have clean (no file inside.) It is a long process so bear with me.

Part 1. Creating Recovery Image from source

1. Create Clonezilla Live Boot in USB1 using Tuxboot as mention in here.
2. Plug USB1 to source machine. Boot up source machine with USB1. (You need to configure USB1 as USB-HDD and first in boot-priority in BIOS).
3. Clonezilla Live Boot Menu will appear. Choose “Other modes of Clonezilla live“.
4. Choose “To RAM. Boot media can be removed later” option.
5. Choose “English” for language
6. Choose “Don’t touch keymap” for keyboard.
7. And start Clonezilla by “Start_Clonezilla“.
8. Choose “device-image” because we are creating recovery images
9. Choose “local_dev” since we intend to save image file to USB1.
10. If you want to save your image to other USB disk, please plug in that step and press “Enter”.
But now we are re-using “USB1″ to save images, we don’t need another USB disk right now.
11. Next, choose USB1 as destination for images. Normally selection should be “sdb1” but may vary
according to disks and partitions. So please make sure you select correct disk other than “sda”.
12. Choose directory for images. We let it save in root of our USB1 drive.
13. Press “Enter” to confirm.
14. Choose “Beginner“.
15. Choose “savedisk“.
16. Give image name and press “Enter”.
17. Next, let the default setting for the rest of questions and confirmation.
18. You will see progress of creating images. Once it finished, you can do “Poweroff” or “Reboot“.

You will get image as folder on your root of USB1 with your given name.

Part 2. Creating ISO file

1. Move newly created image folder from USB1 to root of USB2.
2. Again, plug USB1 into source machine and Boot up from USB1.
3. Clonezilla Live Boot Menu will appear. Choose “Default settings” this time. (“To RAM option will
not work for ISO creation.)
4. Choose “Language” and “Keyboard” as in part1 and Start Clonezilla.
5. Choose “device-image
6. Choose “local_dev
7. IMPORTANCE step. Before press “Enter”, plug in USB2 and wait for 5 seconds and then press
“Enter”.
8. Select USB2 as image repository. (Usually will show as sdc1~~ since USB1 will be sdb1).
9. Confirm the disk and choose “Beginner
10. Choose “recovery-iso-zip“. (If USB2 doesn’t have image folder in its root, this option will not be
shown, so make sure you move image folder from USB1 to USB2 as stated on number 1 of this part.)
11. Select image and press Enter
12. Select default for next 3 questions.
13. Select “iso” for recovery type.
14. It will take some time and once it finished, you will need to press “Enter” and then can choose
Reboot” or “Poweroff“.
15. You will get “iso” file in USB2 root folder.

Using another PC (or maybe source machine), copy image folder and iso file into local disk and
remove both of them from USB2.

Part3. Final Step: Creating USB Recovery disk

1. Open “Tuxboot“, this time choose “Pre Downloaded” and ISO and locate the iso file you just
move to local disk.
2. Choose Device Driver of USB2 and press “OK”.

Recovery Image will be created in USB2.

Extra: If you want to restore/clone,
1. just plug in and boot from USB2
2. Select first option in Menu (which is the image your created in Part 1 and 2).
3. Perss “y” and “Enter” and “y” and “Enter”
4. Wait for restore process to complete
5. Reboot your machine and your local disk will be restored or cloned.

Resource :
(1) Clonezilla Live on USB
(2) Save disk image
(3) Create Recovery Clonzilla

Thunderbird RSS Feed as Simple Text

I am sure everyone knew Mozilla Thunderbird is not only a mail client but also a RSS Feed reader. And if you are configuring RSS Feed of your favorite blog or website in Thunderbird and found out that this RSS Feed is loaded as web page — not as simple text, here is the solution:

  1.   Go to Tools –> Options –> Advanced –>Config Editor.
  2.   If you are prompted a warning message, just process.
  3.   Search for  rss.show.content-base in Search bar on top.
  4.   Change the value “0” to “1” (default is “0”).

After changing this, your RSS Feed will be shown as simple text.

The reason I want to show my RSS Feed as simple text but not a web page is that, the web page or blog has many many unnecessary things such as widgets, list of most recent post, etc and even worst adv! And I also feel loading time is slower. If I want to see such list and advertisement and widgets, I would go to their website directly from my browser. All I want to see is content ONLY. :) Moreover, the option “By default, show article summary instead of loading the web page” from News Feeds–>Settings, is not working as expected. So I need to go into the config and edit the settings.

I hope it’ll help who have same issue with me.

November ipad app with sucking ios6

Unexpectedly I am writing ipad app. Unexpectedly I brought $99 apple developer program sponsor by my company. My company wants ipad app as “ordering terminal” to communicate with existing POS system. They expected to have it in one month! Nobody wants to do it so I, nosy to learn in technology, took it.

So I need to learn Objective C to develop ipad app. Learning Objective C is not hard as I though previously. If you are expert in C/C++, it is very easy to learn. And if you know the basic concept of MVC, then it is a lot easier! As my app is only a simple one, I think, I can learn pretty easy. Now over two weeks, i can say most functions of app are done. I don’t have much time for UI, so I used only existing library. Even these UI are good and very powerful.

What I like most about objective C is that they are derived from C/C++ . Its compiler can compile C++ program. It means as a nature of C programs, it can run lightly and smoothly. That’s why iPhone and ipad apps have greater graphic compare to android. Also memory management is far greater. It’s from the end-user point of view.

By the way, I am so upsetting current ios6. Yes! because of font fallback system! Normally, android and others go and find into a fallback font if they cannot find one character. But in ios6, it looks for one missing character into ALL other fonts!! Result is if you open somethings that contain Myanmar character, you have to wait until it finished searching. Unacceptably take long time. In my experience, Notes app crashed, Calendar app cannot open. Have to wait 5 minutes to show the first post of Facebook.

OK. Enough this time. I write again because I haven’t written long time. I try to push my self to write more frequently.

Install SQLite3 in CentOS

Just to make sure that I remember what I did when SQLite3 driver was missing when I installed [or upgraded] php on the CentOS server.

  1. Install php

    yum install httpd httpd-devel

  2. check sqlite version

    yum info sqlite

  3. Install compiler to compile the sqlite3 driver

    yum install gcc

  4. Update the php-devel

    rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
    yum –enablerepo=webtatic update php-devel

  5. Download and extract difference php version

    wget http://de.php.net/get/php-5.3.6.tar.gz/from/this/mirror
    tar zxvf php-5.3.6.tar.gz

  6. Go to sqlite3 folder in newly downloaded php folder and copy/rename config file.

    cd php-5.3.6/ext/sqlite3/
    cp config0.m4 config.m4

  7. then compile

    phpize
    ./configure
    make
    make install

     

  8. We will get sqlite3.so. We need to point that driver in php. So we create the file “/etc/php.d/sqlite3.ini” which has

    extension=sqlite3.so

  9. Finally, we restart the apache.

    /etc/init.d/httpd restart

    You can able to connect to sqlite database now. :)

ref: stackoverflow and bnode.org

Quick ‘n’ Easy LAMP Server For CentOS/RHEL

freezing yum :)

Have you encounter where terminal become freeze or hung when you run “yum” in CentOS?

Here is how I recover from it.

rm -f /var/lib/rpm/__db*
rpm -vv --rebuilddb

Suggestion found from here.