Thursday, October 16, 2014
Install UNIX Version 1 (1972) on Linux
Wednesday, October 15, 2014
Nagios - Server Monitoring
Setup
Notice
- restart apache after add new config file for Nagios
- update your email address in contacts.cfg (in order to receive the mail)
Wednesday, October 1, 2014
Stack Buffer Overflow
Problem
void do_magic(char *buf,int n){
int i;
srand(time(NULL));
for(i=0;i<n;i++)
buf[i] ^= rand()%256;
}
void magic(){
char magic_str[60];
scanf("%s",magic_str);
do_magic(magic_str,strlen(magic_str));
printf("%s",magic_str);
}
Analysis
[Solution 1] Disassemble the bin file.
- objdump: objdump -d magic
- Online decompiler: http://decompiler.fit.vutbr.cz/decompilation-run/
- IDA Pro
08048681 <magic>: 8048681: 55 push %ebp 8048682: 89 e5 mov %esp,%ebp 8048684: 83 ec 58 sub $0x58,%esp 8048687: 8d 45 bc lea -0x44(%ebp),%eax 804868a: 89 44 24 04 mov %eax,0x4(%esp) 804868e: c7 04 24 36 88 04 08 movl $0x8048836,(%esp) 8048695: e8 66 fe ff ff call 8048500 <__isoc99_scanf@plt>
We can learn that the character array size would be 0x44 = 68. And, should add 4 for frame pointer.
*note: "ESP is the current stack pointer. EBP is the base pointer for the current stack frame."
[Solution 2] GDB debug analysis
Dump of assembler code for function magic: 0x08048681 <+0>: push %ebp 0x08048682 <+1>: mov %esp,%ebp 0x08048684 <+3>: sub $0x58,%esp 0x08048687 <+6>: lea -0x44(%ebp),%eax 0x0804868a <+9>: mov %eax,0x4(%esp) 0x0804868e <+13>: movl $0x8048836,(%esp) 0x08048695 <+20>: call 0x8048500 <__isoc99_scanf@plt> => 0x0804869a <+25>: lea -0x44(%ebp),%eax 0x0804869d <+28>: mov %eax,(%esp) 0x080486a0 <+31>: call 0x80484d0 <strlen@plt> 0x080486a5 <+36>: mov %eax,0x4(%esp) 0x080486a9 <+40>: lea -0x44(%ebp),%eax 0x080486ac <+43>: mov %eax,(%esp) 0x080486af <+46>: call 0x8048621 <do_magic> 0x080486b4 <+51>: lea -0x44(%ebp),%eax 0x080486b7 <+54>: mov %eax,0x4(%esp) 0x080486bb <+58>: movl $0x8048836,(%esp) 0x080486c2 <+65>: call 0x8048460 <printf@plt> 0x080486c7 <+70>: leave 0x080486c8 <+71>: ret
eax 0x1 1 ecx 0x1 1 edx 0xf7fb88c4 -134510396 ebx 0xf7fb6ff4 -134516748 esp 0xffffd560 0xffffd560 ebp 0xffffd5b8 0xffffd5b8 esi 0x0 0 edi 0x0 0 eip 0x804869a 0x804869a <magic+25> eflags 0x286 [ PF SF IF ] cs 0x23 35 ss 0x2b 43 ds 0x2b 43 es 0x2b 43 fs 0x0 0 gs 0x63 99
Try different size of inputs until ebp is modified, and we can know the size for stack buffer overflow.
Solution
- ( python ... && cat ) is designed for not passing EOF to nc, which may close the connection before we interact with it.
- \x0e\x86\x04\x08 is the address of the function we want the program to run, and it's indicated in little endian.
Reference
Tuesday, August 12, 2014
Paper, Slingshot, Snapchat
Paper (Facebook)
Its UI is never seem at other place, and the user is having different sections to follow. Folding and unfolding interface is very fun and user-friendly.
Slingshot (Facebook)
It's released on 7/31, 2014, which is pretty new at this point. Facebook is trying to create a new photo-based IM experience. This may be inspired by Snapchat.
Snapchat (Rejected Facebook's $3 Billion Offer)
Snapchat is pretty famous for rejecting Facebook's $3 Billion offer, and it's popular for teenagers. It's fun, you are having a pretty light chatting experience, and don't have to worry too much on telling secrets. Ha.
If You Can't Find Them on App Store...
- Click on "Apple ID" at the bottom of "Featured" tab in App Store
- Click on "View Apple ID", it may request for your password
- Click on "Country/Region", pick "United State", and you will set them up correctly by pressing many times of "Next" button
Reference
Sunday, June 29, 2014
PaaS: Google AppEngine v.s. Heroku
Reference
- http://www.scriptrock.com/articles/heroku-appengine
- https://news.ycombinator.com/item?id=4573685
- http://kmilo0.blogspot.tw/2013/02/gae-vs-heroku.html
Intro
Comparison
Language Support
Heroku: Ruby, Java, Node.js, Python, PHP, Clojure, Scala / PostgreSQL, MongoDB, Cloudant, Redis
Comments for Google AppEngine
AppEngine’s proprietary, read-only nature results in tedious and unnecessary code refactoring; apps have to be written specifically with AppEngine in mind, API’s have to be written specifically for AppEngine, even standard Java code has to be extensively altered to fit into the AppEngine environment.
Google insists on AppEngine customers only using its BigTable non-relational database, although they have also recently added some support for CloudSQL.
Comments for Heroku
Heroku’s database-platform choices reflect a collection that is in widespread use already in the wider world.
Comments on Both
Heroku’s database-platform choices reflect a collection that is in widespread use already in the wider world.
My Summary
IaaS, PaaS, SaaS
Intro
SaaS: Software as a Service
Examples
- Gmail
- Google+
PaaS: Platform as a Service
One can develop applications and let them execute on top of the platform which take care of the execution.
Vendors manage:
- runtime
- middleware
- O/S
- virtualizatoin
- server
- storage
- networking
Users manage:
- application
- data
Examples
- Heroku
- Google App Engine
IaaS: Infrastructure as a Service
Users buy fully outsource service (the whole virtual machine)
Examples
- AWS(Amazon Web Services)
- Linode
Reference
Friday, June 13, 2014
SYN Flood DDOS Defense in Kernel Code
Environment
Knowledge
To start a connection between a server and a client, they have to perform "TCP 3-Way Handshake" first without any failure:
- client -> server: SYN
- server -> client: SYN-ACK
- client -> server: ACK
However, not everyone in the internet is friendly and follow every rule we have. An attacker may only send SYN-package (first step in the 3-Way Handshake) but with pretty large amount, the server then may run out of resource since there are too many half-open connections. And, the attacker can even apply random IP source in the packages so that the server is not able to distinguish the bad/good clients.
Preface
However, of course, the capability is limit, Kernel has to dropped some request sockets to allow new sockets with the table is full. In the original Kernel code, it kills old sockets every 0.2 second in net/ipv4/inet_connection_sock.c:inet_csk_reqsk_queue_prune.
Comparing to the original code, in this last OSDI lab, we are not relied on the regular routine to drop old request sockets, but we are randomly dropping a socket in the table when a new socket request comes and the table is full.
Implementation
Modify the Original Pruning Routine
In net/ipv4/inet_connection_sock.c:inet_csk_reqsk_queue_prune add following in line 513: thresh = max_retries;
Randomly Dropping Socket when Is Full
After tracing the code, we know that the function reqsk_queue_is_full is called whenever the TCP program wants to add a new sock in the request queue. So we simply add some code in the this function.static inline int reqsk_queue_is_full(struct request_sock_queue *queue)
{
struct listen_sock *lopt = queue->listen_opt;
struct request_sock **reqp, *req;
int i, range, random;
unsigned long now = jiffies;
int r = (queue->listen_opt->qlen >> queue->listen_opt->max_qlen_log);
printk("[OSDI] qlen = %d\n", lopt->qlen);
if( r ) {
range = lopt->nr_table_entries;
printk("range = %d\n", range);
random %= range;
get_random_bytes(&random, sizeof(range));
i = lopt->clock_hand;
do {
i = (i + 1) & (lopt->nr_table_entries - 1);
} while (--random > 0);
printk("i=%d first is killed\n", i);
reqp=&lopt->syn_table[i];
if ((req = *reqp) != NULL) {
if (time_after_eq(now, req->expires)) {
/* OSDI lab12 */
reqsk_queue_unlink(queue, req, reqp);
reqsk_queue_removed(queue, req);
reqsk_free(req);
}
}
lopt->clock_hand = i;
}
// get the result again
return queue->listen_opt->qlen >> queue->listen_opt->max_qlen_log;
}
We first calculate the original result for is_full or not. If it's full, then we random pick on queue entry from the table and drop the first element of the queue.
Test
Method 1 - Use iptables (Firewall)
sudo iptables -A INPUT -s <SERVER_IP> -j REJECT
Method 2 - Use hping3
sudo hping3 -i u1 -S -c 10 <SERVER_IP>
Another DDOS Experiment in our Workshop
The attacked server (right-hand side) is having a high CPU usage while another server (left-hand side) is send SYN Flood packages.
