r6
| 1 | [[분류:Aidenk]] |
|---|
| 2 | [목차] |
|---|
r1
| 3 | == 개요 == |
|---|
| 4 | 특정 서버나 네트워크에 과도한 트래픽을 발생시켜 정상적인 서비스 제공을 방해하는 사이버 공격. |
|---|
| 5 | |
|---|
r12
| 6 | 원리는 requests로 서버에 과부화를 주는 것. --사실상 이코드로 DDos 공격은 불가능이다. 애초에 구글 도메인에 get을 해야하기에...-- |
|---|
r1
| 7 | |
|---|
r8
| 8 | 신기하게 깃허브에는 DDOS 코드가 존재한다... |
|---|
| 9 | |
|---|
r16
| 10 | ==# 예시 코드 #== |
|---|
r17
| 11 | 이게 디도스가 맞나... 싶을 정도로 그냥 트래픽만 늘리는... post를 get으로 바꾸어야 정상적을 받을 수 있다. |
|---|
r21
| 12 | 그냥 API 보내고 받을때 쓰는 아주 기초적인 코드다. |
|---|
r15
| 13 | |
|---|
r14
| 14 | * python |
|---|
r1
| 15 | {{{#!syntax python |
|---|
| 16 | import requests |
|---|
| 17 | |
|---|
r4
| 18 | url = "https://www.google.com" |
|---|
r1
| 19 | |
|---|
| 20 | for i in range(1): |
|---|
r9
| 21 | a = requests.post(url) |
|---|
r5
| 22 | |
|---|
| 23 | print(a) |
|---|
| 24 | print(a.text) |
|---|
r6
| 25 | }}} |
|---|
| 26 | |
|---|
r14
| 27 | * c# |
|---|
r10
| 28 | {{{#!syntax csharp |
|---|
| 29 | using System; |
|---|
| 30 | using System.Net.Http; |
|---|
| 31 | using System.Threading.Tasks; |
|---|
| 32 | |
|---|
| 33 | class Program |
|---|
| 34 | { |
|---|
| 35 | static async Task Main(string[] args) |
|---|
| 36 | { |
|---|
| 37 | string url = "https://www.google.com"; |
|---|
| 38 | |
|---|
| 39 | using (HttpClient client = new HttpClient()) |
|---|
| 40 | { |
|---|
| 41 | HttpResponseMessage response = await client.PostAsync(url, null); |
|---|
| 42 | |
|---|
| 43 | Console.WriteLine(response); |
|---|
| 44 | string text = await response.Content.ReadAsStringAsync(); |
|---|
| 45 | Console.WriteLine(text); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | } }}} |
|---|
r14
| 49 | |
|---|
| 50 | * cpp |
|---|
r10
| 51 | {{{#!syntax cpp |
|---|
r11
| 52 | #include <iostream> |
|---|
| 53 | #include <string> |
|---|
| 54 | #include <curl/curl.h> |
|---|
r10
| 55 | |
|---|
r11
| 56 | size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* buffer) { |
|---|
| 57 | size_t totalSize = size * nmemb; |
|---|
| 58 | buffer->append((char*)contents, totalSize); |
|---|
| 59 | return totalSize; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | int main() { |
|---|
| 63 | CURL* curl; |
|---|
| 64 | CURLcode res; |
|---|
| 65 | std::string response; |
|---|
| 66 | |
|---|
| 67 | curl = curl_easy_init(); |
|---|
| 68 | |
|---|
| 69 | if (curl) { |
|---|
| 70 | curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com"); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | curl_easy_setopt(curl, CURLOPT_POST, 1L); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); |
|---|
| 77 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | res = curl_easy_perform(curl); |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | std::cout << "Response Code: " << res << std::endl; |
|---|
| 84 | std::cout << "Response Text:\n" << response << std::endl; |
|---|
| 85 | |
|---|
| 86 | curl_easy_cleanup(curl); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | return 0; |
|---|
| 90 | } |
|---|
r10
| 91 | }}} |
|---|
| 92 | |
|---|
r14
| 93 | * ruby |
|---|
r13
| 94 | {{{#!syntax ruby |
|---|
| 95 | require 'net/http' |
|---|
| 96 | require 'uri' |
|---|
| 97 | |
|---|
| 98 | url = URI.parse("https://www.google.com") |
|---|
| 99 | |
|---|
| 100 | http = Net::HTTP.new(url.host, url.port) |
|---|
| 101 | http.use_ssl = true |
|---|
| 102 | |
|---|
| 103 | request = Net::HTTP::Post.new(url.request_uri) |
|---|
| 104 | |
|---|
| 105 | response = http.request(request) |
|---|
| 106 | |
|---|
| 107 | puts response |
|---|
| 108 | puts response.body |
|---|
| 109 | }}} |
|---|
r14
| 110 | |
|---|
| 111 | * java |
|---|
| 112 | {{{#!syntax java |
|---|
| 113 | import java.net.URI; |
|---|
| 114 | import java.net.http.HttpClient; |
|---|
| 115 | import java.net.http.HttpRequest; |
|---|
| 116 | import java.net.http.HttpResponse; |
|---|
| 117 | |
|---|
| 118 | public class Main { |
|---|
| 119 | public static void main(String[] args) throws Exception { |
|---|
| 120 | String url = "https://www.google.com"; |
|---|
| 121 | |
|---|
| 122 | HttpClient client = HttpClient.newHttpClient(); |
|---|
| 123 | |
|---|
| 124 | HttpRequest request = HttpRequest.newBuilder() |
|---|
| 125 | .uri(URI.create(url)) |
|---|
| 126 | .POST(HttpRequest.BodyPublishers.noBody()) |
|---|
| 127 | .build(); |
|---|
| 128 | |
|---|
| 129 | HttpResponse<String> response = |
|---|
| 130 | client.send(request, HttpResponse.BodyHandlers.ofString()); |
|---|
| 131 | |
|---|
| 132 | System.out.println(response); |
|---|
| 133 | System.out.println(response.body()); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | }}} |
|---|
r17
| 137 | |
|---|
| 138 | * JS |
|---|
| 139 | {{{#!syntax javascript |
|---|
| 140 | const url = "https://www.google.com"; |
|---|
| 141 | |
|---|
| 142 | fetch(url, { |
|---|
| 143 | method: "POST" |
|---|
| 144 | }) |
|---|
| 145 | .then(res => res.text()) |
|---|
| 146 | .then(text => { |
|---|
| 147 | console.log(text); |
|---|
| 148 | }) |
|---|
| 149 | .catch(err => { |
|---|
| 150 | console.error(err); |
|---|
| 151 | }); |
|---|
| 152 | }}} |
|---|
r18
| 153 | |
|---|
| 154 | * Visual Basic --이거 쓰는 사람이 아직 있을까...-- |
|---|
| 155 | {{{#!syntax python |
|---|
| 156 | Imports System |
|---|
| 157 | Imports System.Net.Http |
|---|
| 158 | Imports System.Threading.Tasks |
|---|
| 159 | |
|---|
| 160 | Module Module1 |
|---|
| 161 | Sub Main() |
|---|
| 162 | PostRequest().Wait() |
|---|
| 163 | End Sub |
|---|
| 164 | |
|---|
| 165 | Async Function PostRequest() As Task |
|---|
| 166 | Dim url As String = "https://www.google.com" |
|---|
| 167 | Dim client As New HttpClient() |
|---|
| 168 | |
|---|
| 169 | Dim response As HttpResponseMessage = |
|---|
| 170 | Await client.PostAsync(url, Nothing) |
|---|
| 171 | |
|---|
| 172 | Console.WriteLine(response) |
|---|
| 173 | |
|---|
| 174 | Dim text As String = Await response.Content.ReadAsStringAsync() |
|---|
| 175 | Console.WriteLine(text) |
|---|
| 176 | End Function |
|---|
| 177 | End Module |
|---|
| 178 | }}} |
|---|
r19
| 179 | |
|---|
| 180 | * GO |
|---|
| 181 | {{{#!syntax go |
|---|
| 182 | package main |
|---|
| 183 | |
|---|
| 184 | import ( |
|---|
| 185 | "fmt" |
|---|
| 186 | "io/ioutil" |
|---|
| 187 | "net/http" |
|---|
| 188 | ) |
|---|
| 189 | |
|---|
| 190 | func main() { |
|---|
| 191 | url := "https://www.google.com" |
|---|
| 192 | |
|---|
| 193 | resp, err := http.Post(url, "application/x-www-form-urlencoded", nil) |
|---|
| 194 | if err != nil { |
|---|
| 195 | fmt.Println("error:", err) |
|---|
| 196 | return |
|---|
| 197 | } |
|---|
| 198 | defer resp.Body.Close() |
|---|
| 199 | |
|---|
| 200 | fmt.Println(resp) |
|---|
| 201 | |
|---|
| 202 | body, _ := ioutil.ReadAll(resp.Body) |
|---|
| 203 | fmt.Println(string(body)) |
|---|
| 204 | } |
|---|
| 205 | }}} |
|---|
| 206 | |
|---|
r20
| 207 | * windows CMD |
|---|
| 208 | {{{curl -X POST "https://www.google.com"}}} |
|---|
| 209 | |
|---|
| 210 | * PowerShell |
|---|
| 211 | {{{#!syntax powershell |
|---|
| 212 | $url = "https://www.google.com" |
|---|
| 213 | |
|---|
| 214 | $response = Invoke-WebRequest -Uri $url -Method Post |
|---|
| 215 | |
|---|
| 216 | $response |
|---|
| 217 | |
|---|
| 218 | $response.Content |
|---|
| 219 | }}} |
|---|
| 220 | |
|---|
| 221 | * TypeScript |
|---|
| 222 | {{{#!syntax typescript |
|---|
| 223 | const url: string = "https://www.google.com"; |
|---|
| 224 | |
|---|
| 225 | fetch(url, { method: "POST" }) |
|---|
| 226 | .then((res: Response) => res.text()) |
|---|
| 227 | .then((text: string) => { |
|---|
| 228 | console.log(text); |
|---|
| 229 | }) |
|---|
| 230 | .catch((err: any) => { |
|---|
| 231 | console.error(err); |
|---|
| 232 | }); |
|---|
| 233 | }}} |
|---|
| 234 | |
|---|
| 235 | |
|---|
r6
| 236 | == 범죄 == |
|---|
| 237 | 사이버 공격은 엄연한 범죄이다. |
|---|