Skip to content

Instantly share code, notes, and snippets.

@a-r-g-v
Last active December 24, 2017 13:55
Show Gist options
  • Save a-r-g-v/54a48936a6e0c5112eaa to your computer and use it in GitHub Desktop.
Save a-r-g-v/54a48936a6e0c5112eaa to your computer and use it in GitHub Desktop.
脆弱なunboundの作り方

脆弱なunboundの作り方

DNSに対する攻撃の勉強として、脆弱なキャッシュDNSサーバがほしいという時がある。 ここでは,以下の特性を持つな、脆弱なunboundに改変する方法を記載する。

  • source port randomization が無効
  • transaction id の幅が小さい

対象versionは、 unbound-1.5.3である。

disable source port randomization

config で対応できる

server:
  outgoing-port-avoid:1024-65533
  outgoing-port-permit: 65534-65535

上記のように記述すると,送信元ポート番号として65534と65535しか選択されない.

transaction id

ソースコードを弄った unbound-1.5.3/services/outside_network.c の 907 ~ 932 行

/** Select random ID */
static int
select_id(struct outside_network* outnet, struct pending* pend,
        sldns_buffer* packet)
{
        int id_tries = 0;
        pend->id = ((unsigned)ub_random(outnet->rnd)>>8) & 0xffff;
        LDNS_ID_SET(sldns_buffer_begin(packet), pend->id);

        /* insert in tree */
        pend->node.key = pend;
        while(!rbtree_insert(outnet->pending, &pend->node)) {
                /* change ID to avoid collision */
                pend->id = ((unsigned)ub_random(outnet->rnd)>>8) & 0xffff;
                LDNS_ID_SET(sldns_buffer_begin(packet), pend->id);
                id_tries++;
                if(id_tries == MAX_ID_RETRY) {
                        pend->id=99999; /* non existant ID */
                        log_err("failed to generate unique ID, drop msg");
                        return 0;
                }
        }
        verbose(VERB_ALGO, "inserted new pending reply id=%4.4x", pend->id);
        return 1;
}

((unsigned)ub_random(outnet->rnd)>>8) と AND を 0xffff ではなく, 好きな値(0x1fとか)に変更すると,ちょうど良い

お好みで, 1144行のANDも変更してあげると良い.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment