|
| 1 | +<!-- livebook:{"persist_outputs":true} --> |
| 2 | + |
1 | 3 | # ESCT: Part 2 - OWASP
|
2 | 4 |
|
3 | 5 | ```elixir
|
4 |
| -Mix.install([ |
5 |
| - {:grading_client, path: "#{__DIR__}/grading_client"}, |
6 |
| - :bcrypt_elixir, |
7 |
| - :httpoison, |
8 |
| - {:absinthe, "~> 1.7.0"}, |
9 |
| - {:phoenix, "~> 1.0"}, |
10 |
| - {:plug, "~> 1.3.2"} |
11 |
| -]) |
| 6 | +Mix.install( |
| 7 | + [ |
| 8 | + {:grading_client, path: "#{__DIR__}/grading_client"} |
| 9 | + ], |
| 10 | + config_path: "#{__DIR__}/grading_client/config/config.exs" |
| 11 | +) |
12 | 12 |
|
13 | 13 | md5_hash = :crypto.hash(:md5, "users_password")
|
14 | 14 | bcrypt_salted_hash = Bcrypt.hash_pwd_salt("users_password")
|
@@ -103,27 +103,56 @@ Notable CWEs included are CWE-259: Use of Hard-coded Password, CWE-327: Broken o
|
103 | 103 |
|
104 | 104 | _Please uncomment the function call that you believe is correct._
|
105 | 105 |
|
| 106 | +<!-- livebook:{"attrs":"eyJtb2R1bGVfaWQiOm51bGwsInF1ZXN0aW9uX2lkIjpudWxsLCJzb3VyY2UiOiJkZWZtb2R1bGUgUGFzc3dvcmRDb21wYXJlIGRvXG4gIGRlZiBvcHRpb25fb25lKHBhc3N3b3JkLCBtZDVfaGFzaCkgZG9cbiAgICBjYXNlIDpjcnlwdG8uaGFzaCg6bWQ1LCBwYXNzd29yZCkgPT0gbWQ1X2hhc2ggZG9cbiAgICAgIHRydWUgLT4gOmVudHJ5X2dyYW50ZWRfb3AxXG4gICAgICBmYWxzZSAtPiA6ZW50cnlfZGVuaWVkX29wMVxuICAgIGVuZFxuICBlbmRcblxuICBkZWYgb3B0aW9uX3R3byhwYXNzd29yZCwgYmNyeXB0X3NhbHRlZF9oYXNoKSBkb1xuICAgIGNhc2UgQmNyeXB0LnZlcmlmeV9wYXNzKHBhc3N3b3JkLCBiY3J5cHRfc2FsdGVkX2hhc2gpIGRvXG4gICAgICB0cnVlIC0+IDplbnRyeV9ncmFudGVkX29wMlxuICAgICAgZmFsc2UgLT4gOmVudHJ5X2RlbmllZF9vcDJcbiAgICBlbmRcbiAgZW5kXG5lbmRcblxuIyBETyBOT1QgQ0hBTkdFIENPREUgQUJPVkUgVEhJUyBMSU5FID09PT09PT09PT09PT09PT09PT09PT09PT1cblxuIyBQYXNzd29yZENvbXBhcmUub3B0aW9uX29uZShcInVzZXJzX3Bhc3N3b3JkXCIsIG1kNV9oYXNoKVxuIyBQYXNzd29yZENvbXBhcmUub3B0aW9uX3R3byhcInVzZXJzX3Bhc3N3b3JkXCIsIGJjcnlwdF9zYWx0ZWRfaGFzaCkifQ","chunks":[[0,178],[180,859]],"kind":"Elixir.GradingClient.GradedCell","livebook_object":"smart_cell"} --> |
| 107 | + |
106 | 108 | ```elixir
|
107 |
| -defmodule PasswordCompare do |
108 |
| - def option_one(password, md5_hash) do |
109 |
| - case :crypto.hash(:md5, password) == md5_hash do |
110 |
| - true -> :entry_granted_op1 |
111 |
| - false -> :entry_denied_op1 |
| 109 | +module_id = Kino.Input.select("Module", [{OWASP, "OWASP"}]) |
| 110 | +question_id = Kino.Input.number("Question ID") |
| 111 | +Kino.render(Kino.Layout.grid([module_id, question_id], columns: 2)) |
| 112 | +nil |
| 113 | + |
| 114 | +module_id = Kino.Input.read(module_id) |
| 115 | +question_id = Kino.Input.read(question_id) |
| 116 | + |
| 117 | +result = |
| 118 | + defmodule PasswordCompare do |
| 119 | + def option_one(password, md5_hash) do |
| 120 | + case :crypto.hash(:md5, password) == md5_hash do |
| 121 | + true -> :entry_granted_op1 |
| 122 | + false -> :entry_denied_op1 |
| 123 | + end |
112 | 124 | end
|
113 |
| - end |
114 | 125 |
|
115 |
| - def option_two(password, bcrypt_salted_hash) do |
116 |
| - case Bcrypt.verify_pass(password, bcrypt_salted_hash) do |
117 |
| - true -> :entry_granted_op2 |
118 |
| - false -> :entry_denied_op2 |
| 126 | + def option_two(password, bcrypt_salted_hash) do |
| 127 | + case Bcrypt.verify_pass(password, bcrypt_salted_hash) do |
| 128 | + true -> :entry_granted_op2 |
| 129 | + false -> :entry_denied_op2 |
| 130 | + end |
119 | 131 | end
|
120 | 132 | end
|
| 133 | + |
| 134 | +case GradingClient.check_answer(module_id, question_id, result) do |
| 135 | + :correct -> |
| 136 | + IO.puts([IO.ANSI.green(), "Correct!", IO.ANSI.reset()]) |
| 137 | + |
| 138 | + {:incorrect, help_text} when is_binary(help_text) -> |
| 139 | + IO.puts([IO.ANSI.red(), "Incorrect: ", IO.ANSI.reset(), help_text]) |
| 140 | + |
| 141 | + _ -> |
| 142 | + IO.puts([IO.ANSI.red(), "Incorrect.", IO.ANSI.reset()]) |
121 | 143 | end
|
| 144 | +``` |
122 | 145 |
|
123 |
| -# DO NOT CHANGE CODE ABOVE THIS LINE ========================= |
| 146 | +<!-- livebook:{"output":true} --> |
124 | 147 |
|
125 |
| -# PasswordCompare.option_one("users_password", md5_hash) |
126 |
| -# PasswordCompare.option_two("users_password", bcrypt_salted_hash) |
| 148 | +``` |
| 149 | +Incorrect: Research MD5 Rainbow Tables |
| 150 | +``` |
| 151 | + |
| 152 | +<!-- livebook:{"output":true} --> |
| 153 | + |
| 154 | +``` |
| 155 | +:ok |
127 | 156 | ```
|
128 | 157 |
|
129 | 158 | <!-- livebook:{"branch_parent_index":3} -->
|
@@ -244,19 +273,58 @@ Notable CWE included is CWE-1104: Use of Unmaintained Third-Party Components
|
244 | 273 |
|
245 | 274 | ### <span style="color:red">QUIZ</span>
|
246 | 275 |
|
247 |
| -**Which of the outdated components currently installed is vulnerable?** |
| 276 | +**Which of the outdated components listed below is vulnerable?** |
248 | 277 |
|
249 | 278 | _Please change the atom below to the name of the vulnerable package installed in this Livebook AND update the afflicted package._
|
250 | 279 |
|
251 |
| -_HINT: Installed dependencies can be found at the very top, it was the very first cell you ran._ |
| 280 | +_HINT: Check the changelogs for each dependency._ |
| 281 | + |
| 282 | +<!-- livebook:{"attrs":"eyJtb2R1bGVfaWQiOm51bGwsInF1ZXN0aW9uX2lkIjpudWxsLCJzb3VyY2UiOiJhbnN3ZXIgPSBcbiAgS2luby5JbnB1dC5zZWxlY3QoXCJBbnN3ZXJcIiwgW1xuICAgIHs6ZWN0bywgXCJFY3RvIHYyLjIuMlwifSxcbiAgICB7Om54LCBcIk54IHYwLjUuMFwifSxcbiAgICB7OnBsdWcsIFwiUGx1ZyB2MS4zLjJcIn1cbiAgXSlcblxuS2luby5yZW5kZXIoYW5zd2VyKVxuXG5LaW5vLklucHV0LnJlYWQoYW5zd2VyKSJ9","chunks":[[0,178],[180,631]],"kind":"Elixir.GradingClient.GradedCell","livebook_object":"smart_cell"} --> |
252 | 283 |
|
253 | 284 | ```elixir
|
254 |
| -# CHANGE ME |
255 |
| -vulnerable_dependency = :vulnerable_dependency |
| 285 | +module_id = Kino.Input.select("Module", [{OWASP, "OWASP"}]) |
| 286 | +question_id = Kino.Input.number("Question ID") |
| 287 | +Kino.render(Kino.Layout.grid([module_id, question_id], columns: 2)) |
| 288 | +nil |
| 289 | + |
| 290 | +module_id = Kino.Input.read(module_id) |
| 291 | +question_id = Kino.Input.read(question_id) |
| 292 | + |
| 293 | +result = |
| 294 | + ( |
| 295 | + answer = |
| 296 | + Kino.Input.select("Answer", |
| 297 | + ecto: "Ecto v2.2.2", |
| 298 | + nx: "Nx v0.5.0", |
| 299 | + plug: "Plug v1.3.2" |
| 300 | + ) |
| 301 | + |
| 302 | + Kino.render(answer) |
| 303 | + Kino.Input.read(answer) |
| 304 | + ) |
| 305 | + |
| 306 | +case GradingClient.check_answer(module_id, question_id, result) do |
| 307 | + :correct -> |
| 308 | + IO.puts([IO.ANSI.green(), "Correct!", IO.ANSI.reset()]) |
| 309 | + |
| 310 | + {:incorrect, help_text} when is_binary(help_text) -> |
| 311 | + IO.puts([IO.ANSI.red(), "Incorrect: ", IO.ANSI.reset(), help_text]) |
| 312 | + |
| 313 | + _ -> |
| 314 | + IO.puts([IO.ANSI.red(), "Incorrect.", IO.ANSI.reset()]) |
| 315 | +end |
| 316 | +``` |
| 317 | + |
| 318 | +<!-- livebook:{"output":true} --> |
256 | 319 |
|
257 |
| -# DO NOT CHANGE CODE BELOW THIS LINE ============================ |
258 |
| -Application.spec(vulnerable_dependency)[:vsn] |> List.to_string() |> IO.puts() |
259 |
| -IO.puts(vulnerable_dependency) |
| 320 | +``` |
| 321 | +Incorrect: Check the changelog for the next minor or major release. |
| 322 | +``` |
| 323 | + |
| 324 | +<!-- livebook:{"output":true} --> |
| 325 | + |
| 326 | +``` |
| 327 | +:ok |
260 | 328 | ```
|
261 | 329 |
|
262 | 330 | <!-- livebook:{"branch_parent_index":3} -->
|
@@ -389,4 +457,18 @@ case HTTPoison.get(user_inputted_url) do
|
389 | 457 | end
|
390 | 458 | ```
|
391 | 459 |
|
| 460 | +<!-- livebook:{"output":true} --> |
| 461 | + |
| 462 | +``` |
| 463 | +This is the IP belonging to your Livebook instance: |
| 464 | +179.241.241.114 |
| 465 | +
|
| 466 | +``` |
| 467 | + |
| 468 | +<!-- livebook:{"output":true} --> |
| 469 | + |
| 470 | +``` |
| 471 | +:ok |
| 472 | +``` |
| 473 | + |
392 | 474 | [**<- Previous Module: Introduction**](./1-introduction.livemd) || [**Next Module: Secure SDLC Concepts ->**](./3-ssdlc.livemd)
|
0 commit comments