HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2017/09/07

Raspberry Piで Amazon Dash Buttonを自在にハックする方法。tcpdump libpcap方法 Raspberry Piで Amazon Dash Buttonを自在にハックする方法。tcpdump libpcap方法

(ラズパイ + libpcap Packet Capture libraryで Amazon Dash Buttonをハックして IoTする)

Tags: [Raspberry Pi], [電子工作]




● Amazon Dash Buttonとは?

 Amazon Dash Buttonは、ワンプッシュでお気に入りの商品を簡単に注文できるボタンです。
Amazon Dash Button

 あらかじめボタンに紐付けて設定した商品をボタンのワンプッシュの操作で注文する事ができます。
 (Amazonがあらかじめ決めた商品の中から紐付けして、商品の注文が可能です。利用者が自由に好きな商品を設定する事はできません。)

 Dash Buttonは 500円ですが、ボタンを通じた初回注文時にご請求額より500円差し引かれるので Dash Buttonは実質無料となります。
 ※ 500円未満の商品を購入した場合は次回の注文(Amazon扱いのどんな注文でも良い)で残りの金額が差し引かれます。

 詳細はこちら。プロモーション利用規約を確認する
Dash Buttonを500円で購入し、初回注文代金から500円が差し引かれる特典に関する利用規約

 今回はこの Dash Buttonをハックして IoTボタンとして使用する方法を解説します。

 なお、Amazon Dash Buttonはプライム会員専用なのでプライム会員の登録が必要です。

プライム会員の登録はこちらからできます(30日間の無料体験を試す)
 お急ぎ便、お届け日時指定便がいつでも使い放題
 プライムで映画や音楽も楽しめる
 無料体験終了後は、年会費¥3,900(税込)でAmazonプライムをご利用いただけます。無料体験はいつでもキャンセルできます。



● Amazon Dash Buttonを通常の方法で使用する場合の初期設定方法

 IoTハックで Dash Buttonを使用する場合は、
 ・注文する商品を選択しないで初期設定を終了する
 または、
 ・注文する商品を選択した後に、設定メニューでボタンを「無効」にする
 とします。

2017/08/11
Amazon Dash Buttonを普通の方法で使う場合の設定方法と解除方法
Amazon Dash Buttonを普通の方法で使う場合の設定方法と解除方法

  アマゾン ダッシュボタンを普通に登録して、普通に商品を注文する方法(500円割引き)

● Amazon Dash Buttonを IoTハックする場合の設定方法

・Amazon Dash Buttonを IoTハックする場合の設定方法
Amazon Dash Buttonを IoTハックする場合の設定方法
 商品設定の時に商品を設定しないでセットアップを終了します。



● 購入した Amazon Dash Buttonの種類

 500円が勿体無いので実際に商品を購入し、消費する商品の Dash Buttonにしました。

 オススメは、下記の 4種類。商品価格が低いので 500円割引の率が相対的に高いです。


ウィルキンソン Dash Button
ASIN: B01L2WQ27O

フルグラ Dash Button
ASIN: B01L2WPA0O

ラックス (Lux) Dash Button
ASIN: B01L2WOR1C

毎日一杯の青汁 Dash Button
ASIN: B01L2WP6AI


● Node.jsってバージョンが多すぎで訳わかんないよ!

tcpdump -Q in -e arp -q -n
 でコンソール出力をモニタすれば良いじゃん!

 もしくは、わざわざ Nodeで苦労して libpcapしなくても C言語でサラっと書いちゃえば良いじゃん!

Programming with pcap

● libpcapのインストール方法

# Installation and Setup
sudo apt-get update

# Ubuntu and Debian libpcap
sudo apt-get -y install libpcap-dev


● libpcapのサンプル ネットワークのデバイス名を表示

device.c
#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[])
{
  char *dev, errbuf[PCAP_ERRBUF_SIZE];

  dev = pcap_lookupdev(errbuf);
  if (dev == NULL) {
    fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
    return(2);
  }
  printf("Device: %s\n", dev);
  return(0);
}

gcc -lpcap device.c

./a.out
Device: enxb827xxxxxxxx


● libpcapのサンプル ネットワークデバイスを指定してパケットキャプチャが可能かをチェックする

# Opening the device for sniffing

nano sniffing.c
#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[])
{
  char *dev, errbuf[PCAP_ERRBUF_SIZE];

  dev = pcap_lookupdev(errbuf);
  if (dev == NULL) {
    fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
    return(2);
  }
  printf("Device: %s\n", dev);


  pcap_t *handle;

  handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
  if (handle == NULL) {
    fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
    return(2);
  }

  if (pcap_datalink(handle) != DLT_EN10MB) {
    fprintf(stderr, "Device %s doesn't provide Ethernet headers - not supported\n", dev);
    return(2);
  }

  return(0);
}

gcc -lpcap sniffing.c

# sudoを付けて実行する
sudo ./a.out
Device: enxb827xxxxxxxx


● libpcapのサンプル ネットワーク上に流れる ARP要求を検知して MACアドレスを表示する

# Filtering traffic

nano sniff_arp.c
#include <pcap.h>
#include <arpa/inet.h>
#include <stdio.h>

#define ETH_ALEN 6 /* Size of Ethernet address */

/*
 *  This structure defines an ethernet arp header.
 *  /include/uapi/linux/if_arp.h
 */
typedef struct arphdr {
  unsigned short  ar_hrd;    /* format of hardware address  */
  unsigned short  ar_pro;    /* format of protocol address  */
  unsigned char   ar_hln;    /* length of hardware address  */
  unsigned char   ar_pln;    /* length of protocol address  */
  unsigned short  ar_op;     /* ARP opcode (command)      */

  /*
    *   Ethernet looks like this : This bit is variable sized however...
    */
  unsigned char  ar_sha[ETH_ALEN];  /* sender hardware address  */
  unsigned char  ar_sip[4];         /* sender IP address    */
  unsigned char  ar_tha[ETH_ALEN];  /* target hardware address  */
  unsigned char  ar_tip[4];         /* target IP address    */
}arphdr_t;

int main(int argc, char *argv[])
{
  pcap_t *handle;       /* Session handle */
  char *dev;            /* The device to sniff on */
  char errbuf[PCAP_ERRBUF_SIZE];  /* Error string */
  struct bpf_program fp;          /* The compiled filter */
  char filter_exp[] = "port 23";  /* The filter expression */
  bpf_u_int32 mask;        /* Our netmask */
  bpf_u_int32 net;         /* Our IP */
  struct pcap_pkthdr header;    /* The header that pcap gives us */
  const u_char *packet;         /* The actual packet */

  arphdr_t *arpheader = NULL;   /* Pointer to the ARP header              */

  /* Define the device */
  dev = pcap_lookupdev(errbuf);
  if (dev == NULL) {
    fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
    return(2);
  }
  /* Find the properties for the device */
  if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
    fprintf(stderr, "Couldn't get netmask for device %s: %s\n", dev, errbuf);
    net = 0;
    mask = 0;
  }
  /* Open the session in promiscuous mode */
  handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
  if (handle == NULL) {
    fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
    return(2);
  }

  /* Compile and apply the filter */
/*
  if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
    fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
    return(2);
  }
*/
  /* Compiles the filter expression into a BPF filter program */
  if (pcap_compile(handle, &fp, "arp", 1, mask) == -1){
    fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
    return(2);
  }

  if (pcap_setfilter(handle, &fp) == -1) {
    fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle));
    return(2);
  }

  while (1) {
    /* Grab a packet */
    packet = pcap_next(handle, &header);

    /* Print its length */
    //    printf("Jacked a packet with length of [%d]\n", header.len);

    arpheader = (struct arphdr *)(packet+14); /* Point to the ARP header */

    // HTYPE = 1
    if (ntohs(arpheader->ar_hrd) != 1) continue;

    // PTYPE >= 0x0800
    if (ntohs(arpheader->ar_pro) != 0x0800) continue;

    // HLEN = 6
    if (arpheader->ar_hln != 6) continue;

    // PLEN = 4
    if (arpheader->ar_pln != 4) continue;

    // OPER = 1 Request
    if (ntohs(arpheader->ar_op) != 1) continue;

    // SHA Sender Hardware Addres = MAC ADRS.
    printf("Sender MAC: ");
    printf("%02X", arpheader->ar_sha[0]);
    for (int i=1; i<6; ++i)
      printf(":%02X", arpheader->ar_sha[i]);

    printf("\n");
  }

  /* And close the session */
  pcap_close(handle);
  return(0);
}

gcc -lpcap sniff_arp.c

# sudoを付けて実行する
sudo ./a.out
Sender MAC: B4:7C:9C:xx:xx:xx:
Sender MAC: FC:A6:67:xx:xx:xx:
Sender MAC: 68:37:E9:xx:xx:xx:

● tcpdumpで ARPパケットを監視する方法

sudo tcpdump -Q in -e arp -q -n
pi@raspberrypi:~ $ sudo tcpdump -Q in -e arp -q -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enxb827xxxxxxxx, link-type EN10MB (Ethernet), capture size 262144 bytes
15:26:31.459945 68:37:e9:xx:xx:xx > ff:ff:ff:ff:ff:ff, ARP, length 60: Request who-has 192.168.xxx.xxx tell 192.168.1.5, length 46
15:27:08.329785 68:37:e9:xx:xx:xx > ff:ff:ff:ff:ff:ff, ARP, length 60: Request who-has 192.168.xxx.xxx tell 192.168.1.4, length 46
15:27:09.456846 b4:7c:9c:xx:xx:xx > ff:ff:ff:ff:ff:ff, ARP, length 60: Request who-has 192.168.xxx.xxx tell 192.168.1.2, length 46
15:27:13.461632 fc:a6:67:xx:xx:xx > ff:ff:ff:ff:ff:ff, ARP, length 60: Request who-has 192.168.xxx.xxx tell 192.168.1.3, length 46


● tcpdumpを便利に使う為に、tcpdumpのチートシート

tcpdump Cheat Sheet - Comparitech

 Comparitech作成の tcpdumpを便利に使う為の tcpdumpのチートシート。



Tags: [Raspberry Pi], [電子工作]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

TIの 8051マイコン内蔵の BLE CC2540/CC2541を使ってみる
TIの 8051マイコン内蔵の BLE CC2540/CC2541を使ってみる

  Bluetooth Low Energyの SensorTagや iBeacon、CC Debuggerの使い方など

Raspberry Pi 3の Bluetooth BLEで TI SensorTagと接続してセンサーの測定値を読み取る方法
Raspberry Pi 3の Bluetooth BLEで TI SensorTagと接続してセンサーの測定値を読み取る方法

  ラズパイ3の BLEと Node.jsで、TIの SensorTag CC2541DKに接続してセンサーの状態を取得

Raspberry Pi 3の gatttoolのコマンドラインで TIの SensorTagを直接操作する方法
Raspberry Pi 3の gatttoolのコマンドラインで TIの SensorTagを直接操作する方法

  ラズパイ3と gatttoolのコマンドラインで TIの SensorTagに直接接続して gatttoolの使い方を覚える

Raspberry Pi 3に Nodejs blenoをインストールして Bluetooth BLEのペリフェラルを作成する
Raspberry Pi 3に Nodejs blenoをインストールして Bluetooth BLEのペリフェラルを作成する

  ラズパイ3と Node.js blenoで Bluetooth BLEの周辺機器機能を実装する

Raspberry Pi 3の Nodejs blenoで BLE接続して GPIOで Lチカ制御やボタン状態を読み取る
Raspberry Pi 3の Nodejs blenoで BLE接続して GPIOで Lチカ制御やボタン状態を読み取る

  ラズパイ3と Node.js blenoで BLEの周辺機器機能を実装する GPIO編

Raspberry Pi 3の Python BLE pygattlibライブラリで TIの SensorTagに接続して制御する方法
Raspberry Pi 3の Python BLE pygattlibライブラリで TIの SensorTagに接続して制御する方法

  ラズパイ3と Python BLE pygattlibで TIの SensorTagのセンサーの値を取得とボタン状態の通知を受信する

Raspberry Pi 3に Bluetooth BlueZ Version 5.42 BLE
Raspberry Pi 3に Bluetooth BlueZ Version 5.42 BLE

  ラズパイで Bluetooth 4.0の BLE gatt通信を行なう TIの SensorTagや iBeacon実験など

Amazon Dash Buttonをハックして IoTボタンとして使う方法を解説
Amazon Dash Buttonをハックして IoTボタンとして使う方法を解説

  Amazon Dash Buttonをハック。ARP要求を監視、DNSハック、IPアドレスハック等。

Raspberry Piで Amazon Dash Buttonを自在にハックする方法。node-dash-button方法
Raspberry Piで Amazon Dash Buttonを自在にハックする方法。node-dash-button方法

  ラズパイ + Node.jsで Amazon Dash Buttonをハックして IoTボタンとして使う方法を解説

Raspberry Piで Amazon Dash Buttonを自在にハックする方法。Python Scapyライブラリ方法
Raspberry Piで Amazon Dash Buttonを自在にハックする方法。Python Scapyライブラリ方法

  ラズパイ + Python Scapyライブラリで ARPパケット検出からの Amazon Dash Buttonをハック

Raspberry Piで Amazon Dash Buttonを自在にハックする方法。Node.js Dasher方法
Raspberry Piで Amazon Dash Buttonを自在にハックする方法。Node.js Dasher方法

  ラズパイ + Node.js Dasherライブラリで ARPパケット検出からの Amazon Dash Buttonをハック

Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ
Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ

  ラズパイ3で安定して使える microSDカードを購入する Teamと SanDiskは絶対に買わない

Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ

  ラズパイの Raspbian OSのコマンドラインで使用する便利コマンド、負荷試験や CPUシリアル番号の確認方法等も

Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法
Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法

  ラズパイ3の GPIO端子の I2C機能を有効にして各種センサーを繋げる方法まとめ




[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2017 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_amazon_dash_iot_hack_libpcap_tcpdump/