Friday, October 28, 2016

From mirai sources

As you might know, recent huge DDoS attacks (665 Gbit/s) were organized with the help of Mirai malware. Here are some insights into its source code.

Intro

Short overview:
  • Written mainly in C, but some scripts are in golang
  • Loader, payload (bot) and CNC itself can be found in sources
  • IPv6 not supported :( 
Russian trace
This is funny, but in admin.go file there are some Russian sentences:

admin.go: this.conn.Write([]byte("\033[34;1mпользователь\033[33;3m: \033[0m"))
admin.go: this.conn.Write([]byte("\033[34;1mпароль\033[33;3m: \033[0m"))
admin.go: this.conn.Write(append([]byte("\r\033[37;1mпроверив счета... \033[31m"), spinBuf[i % len(spinBuf)]))
admin.go: this.conn.Write([]byte("\r\033[32;1mпроизошла неизвестная ошибка\r\n"))
admin.go: this.conn.Write([]byte("\033[31mнажмите любую клавишу для выхода. (any key)\033[0m"))

How did this happen? All other comments and output info are in English.

Random scan

Mirai authors implemented its own scanning technique, that is very fast, but interesting thing, that it picks IP addresses randomly:

static ipv4_t get_random_ip(void)
{
    uint32_t tmp;
    uint8_t o1, o2, o3, o4;

    do
    {
        tmp = rand_next();

        o1 = tmp & 0xff;
        o2 = (tmp >> 8) & 0xff;
        o3 = (tmp >> 16) & 0xff;
        o4 = (tmp >> 24) & 0xff;
    }
    while (o1 == 127 ||                             // 127.0.0.0/8      - Loopback
          (o1 == 0) ||                              // 0.0.0.0/8        - Invalid address space
          (o1 == 3) ||                              // 3.0.0.0/8        - General Electric Company
          (o1 == 15 || o1 == 16) ||                 // 15.0.0.0/7       - Hewlett-Packard Company
          (o1 == 56) ||                             // 56.0.0.0/8       - US Postal Service
          (o1 == 10) ||                             // 10.0.0.0/8       - Internal network
          (o1 == 192 && o2 == 168) ||               // 192.168.0.0/16   - Internal network
          (o1 == 172 && o2 >= 16 && o2 < 32) ||     // 172.16.0.0/14    - Internal network
          (o1 == 100 && o2 >= 64 && o2 < 127) ||    // 100.64.0.0/10    - IANA NAT reserved
          (o1 == 169 && o2 > 254) ||                // 169.254.0.0/16   - IANA NAT reserved
          (o1 == 198 && o2 >= 18 && o2 < 20) ||     // 198.18.0.0/15    - IANA Special use
          (o1 >= 224) ||                            // 224.*.*.*+       - Multicast 
          (o1 == 6 || o1 == 7 || o1 == 11 || o1 == 21 || o1 == 22 || o1 == 26 || o1 == 28 || o1 == 29 || o1 == 30 || o1 == 33 || o1 == 55 || o1 == 214 || o1 == 215) // Department of Defense
    );

    return INET_ADDR(o1,o2,o3,o4);
}


Nice touch skipping GE, HP, US Post and DoD ;)

Weak and default passwords

Bot brutes weak and default passwords. There are only 63 credentials in there, all like:
add_auth_entry("\x50\x4D\x4D\x56", "\x43\x46\x4F\x4B\x4C", 8);                          // root     admin
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x43\x46\x4F\x4B\x4C", 7);                      // admin    admin
add_auth_entry("\x50\x4D\x4D\x56", "\x1A\x1A\x1A\x1A\x1A\x1A", 6);                      // root     888888

Always change default passwords.

Attack methods


    add_attack(ATK_VEC_UDP, (ATTACK_FUNC)attack_udp_generic);
    add_attack(ATK_VEC_VSE, (ATTACK_FUNC)attack_udp_vse);
    add_attack(ATK_VEC_DNS, (ATTACK_FUNC)attack_udp_dns);
    add_attack(ATK_VEC_UDP_PLAIN, (ATTACK_FUNC)attack_udp_plain);

    add_attack(ATK_VEC_SYN, (ATTACK_FUNC)attack_tcp_syn);
    add_attack(ATK_VEC_ACK, (ATTACK_FUNC)attack_tcp_ack);
    add_attack(ATK_VEC_STOMP, (ATTACK_FUNC)attack_tcp_stomp);

    add_attack(ATK_VEC_GREIP, (ATTACK_FUNC)attack_gre_ip);
    add_attack(ATK_VEC_GREETH, (ATTACK_FUNC)attack_gre_eth);

    //add_attack(ATK_VEC_PROXY, (ATTACK_FUNC)attack_app_proxy);
    add_attack(ATK_VEC_HTTP, (ATTACK_FUNC)attack_app_http);

What's interesting in attacks:

attack_udp_vse 

Attack for Valve game servers?

  • Default payload: TSource Engine Query
  • Default dport: 27015
attack_udp_dns

Not default amplification attack, but attack aimed to authoritative DNS servers of the targeted company. Infected IoT sends the requests to resolve random_string.target.com to ISP service provider, which forwards the request to authoritative server. IoT generates tons of these requests. 

attack_tcp_stomp

This time of attack should bypass mitigation devices. IoT device establishes the TCP connection to target and then sends ACK packets with correct sequence numbers. This keeps the connection alive. Pretty interesting, but should not normally work.

attack_gre_ip & attack_gre_eth

Two attacks with Generic Routing Encapsulation, with and without Ethernet encapsulation. GRE is a good choice, 'cause many routers bypass it without inspection.

That would be all for today. Be paranoid.

Thursday, October 27, 2016

DNS infrastructure evolution

Hello comrade,

today I will show you the DNS infrastructure evolution for a project. This post is dedicated to bind 9.11 stable which was released on the 4th of October.

Few servers

Few - two or more. All registrars request at least two different name servers for a zone.



Add geoIP (with ECS)

Your project grows and you need to land customers from different countries to different frontends. Best way - use geoIP. Based on the IP-address of the client you will return different IP-addresses of your frontends.

ECS - EDNS Client Subnet - one of the extensions mechanisms (EDNS0), described in RFC 7871. Till May 2016 it was just a draft, but is widely used since 2014. If a recursive resolver with ECS feature enabled receives the request, it adds the clients IP into DNS packet and sends the request further. The authorative server returns the IP-address (or any other data) based on the client IP from DNS packet, but not the recursive resolver itself. ECS should be enabled on every server on the way of the request.



As you can see from the picture above, for the request from Chinese client via Google public NS (whose IP-address is treated by geoIP as US) the answer is still 4.3.2.1, as it should be for CN.

GeoIP and ECS are enabled easily in bind:

geoip-directory "/etc/geoip/"; // directory with maxmind .dat file
geoip-use-ecs yes;

and config views like this:
acl US { geoip country US; };
acl CN { geoip country CN; };

view US {
    match-clients { US; };
    zone "yourdomain.com." {
        type slave; 
        file "zones/us_view_yourdomain.com."; 
        masters {blabla; }; 
    };
};

view CN {
    match-clients { CN; };
    zone "yourdomain.com." {
        type slave; 
        file "zones/cn_view_yourdomain.com."; 
        masters {blabla; }; 
    };
};


Add anycast

Now you want to lower the latency between the client and DNS server. Good one. Use BGP anycast. Border routers of the ISPs will route the request to the closest node.


Do not forget to load-balance

Now take care of high-load and redundancy. Add redundant balancers and servers.





Wednesday, October 26, 2016

HSTS preload

Hello comrade,

everybody knows about HSTS - HTTP Strict Transport Security. It is a web security mechanism that is widely used to protect users from protocol downgrade attacks or cookie hijacking.

Works pretty simple:
  1. Servers sends the header Strict-Transport-Security with the max-age parameter. 
  2. Client (browser) sees the header and if it is supported - transforms all insecure links referencing the application into secured. This behavior for this site will be used for the next max-age seconds. 
See RFC 6797 for more details.

But are you paranoid enough? What happens during the very first request to your website, if it is going through HTTP? The client's browser knows nothing about HSTS settings on server's side, thus he is vulnerable.

Solution: HSTS preload. Supported by most major browsers, this technique uses the list, which is built in the browser (just like PKI certificate authorities). If your site is in this list, then the client will use only secured connection to reach it. Important to remember, that HSTS preload affects all subdomains as well (!).

To enable HSTS preload to your website, go to https://hstspreload.appspot.com . There enter your website and follow the instructions. Most likely you will have to modify your HSTS header and make it look like this:

Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

Be paranoid.