这是一个本人学习 csapp 的 learning 库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

452 rivejä
18 KiB

2 vuotta sitten
  1. #######################################################
  2. # CS:APP Bomb Lab
  3. # Directions to Instructors
  4. #
  5. # Copyright (c) 2003-2016, R. Bryant and D. O'Hallaron
  6. #
  7. #######################################################
  8. This directory contains the files that you will use to build and run
  9. the CS:APP Bomb Lab. The Bomb Lab teaches students principles of
  10. machine-level programs, as well as general debugger and reverse
  11. engineering skills.
  12. ***********
  13. 1. Overview
  14. ***********
  15. ----
  16. 1.1. Binary Bombs
  17. ----
  18. A "binary bomb" is a Linux executable C program that consists of six
  19. "phases." Each phase expects the student to enter a particular string
  20. on stdin. If the student enters the expected string, then that phase
  21. is "defused." Otherwise the bomb "explodes" by printing "BOOM!!!".
  22. The goal for the students is to defuse as many phases as possible.
  23. ----
  24. 1.2. Solving Binary Bombs
  25. ----
  26. In order to defuse the bomb, students must use a debugger, typically
  27. gdb or ddd, to disassemble the binary and single-step through the
  28. machine code in each phase. The idea is to understand what each
  29. assembly statement does, and then use this knowledge to infer the
  30. defusing string. Students earn points for defusing phases, and they
  31. lose points (configurable by the instructor, but typically 1/2 point)
  32. for each explosion. Thus, they quickly learn to set breakpoints before
  33. each phase and the function that explodes the bomb. It's a great
  34. lesson and forces them to learn to use a debugger.
  35. ----
  36. 1.3. Autograding Service
  37. ----
  38. We have created a stand-alone user-level autograding service that
  39. handles all aspects of the Bomb Lab for you: Students download their
  40. bombs from a server. As the students work on their bombs, each
  41. explosion and defusion is streamed back to the server, where the
  42. current results for each bomb are displayed on a Web "scoreboard."
  43. There are no explicit handins and the lab is self-grading.
  44. The autograding service consists of four user-level programs that run
  45. in the main ./bomblab directory:
  46. - Request Server (bomblab-requestd.pl). Students download their bombs
  47. and display the scoreboard by pointing a browser at a simple HTTP
  48. server called the "request server." The request server builds the
  49. bomb, archives it in a tar file, and then uploads the resulting tar
  50. file back to the browser, where it can be saved on disk and
  51. untarred. The request server also creates a copy of the bomb and its
  52. solution for the instructor.
  53. - Result Server (bomblab-resultd.pl). Each time a student defuses a
  54. bomb phase or causes an explosion, the bomb sends a short HTTP
  55. message, called an "autoresult string," to an HTTP "result server,"
  56. which simply appends the autoresult string to a "scoreboard log file."
  57. - Report Daemon (bomblab-reportd.pl). The "report daemon" periodically
  58. scans the scoreboard log file. The report daemon finds the most recent
  59. defusing string submitted by each student for each phase, and
  60. validates these strings by applying them to a local copy of the
  61. student's bomb. It then updates the HTML scoreboard that summarizes
  62. the current number of explosions and defusions for each bomb, rank
  63. ordered by the total number of accrued points.
  64. - Main daemon (bomblab.pl). The "main daemon" starts and nannies the
  65. request server, result server, and report deamon, ensuring that
  66. exactly one of these processes (and itself) is running at any point in
  67. time. If one of these processes dies for some reason, the main daemon
  68. detects this and automatically restarts it. The main daemon is the
  69. only program you actually need to run.
  70. ********
  71. 2. Files
  72. ********
  73. The ./bomblab directory contains the following files:
  74. Makefile - For starting/stopping the lab and cleaning files
  75. bomblab.pl* - Main daemon that nannies the other servers & daemons
  76. Bomblab.pm - Bomblab configuration file
  77. bomblab-reportd.pl* - Report daemon that continuously updates scoreboard
  78. bomblab-requestd.pl* - Request server that serves bombs to students
  79. bomblab-resultd.pl* - Result server that gets autoresult strings from bombs
  80. bomblab-scoreboard.html - Real-time Web scoreboard
  81. bomblab-update.pl* - Helper to bomblab-reportd.pl that updates scoreboard
  82. bombs/ - Contains the bombs sent to each student
  83. log-status.txt - Status log with msgs from various servers and daemons
  84. log.txt - Scoreboard log of autoresults received from bombs
  85. makebomb.pl* - Helper script that builds a bomb
  86. scores.txt - Summarizes current scoreboard scores for each student
  87. src/ - The bomb source files
  88. writeup/ - Sample Latex Bomb Lab writeup
  89. *******************
  90. 3. Bomb Terminology
  91. *******************
  92. LabID: Each instance (offering) of the lab is identified by a unique
  93. name, e.g., "f12" or "s13", that the instructor chooses. Explosion and
  94. diffusions from bombs whose LabIDs are different from the current
  95. LabID are ignored. The LabID must not have any spaces.
  96. BombID: Each bomb in a given instance of the lab has a unique
  97. non-negative integer called the "bombID."
  98. Notifying Bomb: A bomb can be compiled with a NOTIFY option that
  99. causes the bomb to send a message each time the student explodes or
  100. defuses a phase. Such bombs are called "notifying bombs."
  101. Quiet Bomb: If compiled with the NONOTIFY option, then the bomb
  102. doesn't send any messages when it explodes or is defused. Such bombs
  103. are called "quiet bombs."
  104. We will also find it helpful to distinguish between custom and
  105. generic bombs:
  106. Custom Bomb: A "custom bomb" has a BombID > 0, is associated with a
  107. particular student, and can be either notifying or quiet. Custom
  108. notifying bombs are constrained to run on a specific set of Linux
  109. hosts determined by the instructor. On the other hand, custom quiet
  110. bombs can run on any Linux host.
  111. Generic Bomb: A "generic bomb" has a BombID = 0, isn't associated with
  112. any particular student, is quiet, and hence can run on any host.
  113. ************************
  114. 4. Offering the Bomb Lab
  115. ************************
  116. There are two basic flavors of Bomb Lab: In the "online" version, the
  117. instructor uses the autograding service to handout a custom notifying
  118. bomb to each student on demand, and to automatically track their
  119. progress on the realtime scoreboard. In the "offline" version, the
  120. instructor builds, hands out, and grades the student bombs manually,
  121. without using the autograding service.
  122. While both version give the students a rich experience, we recommend
  123. the online version. It is clearly the most compelling and fun for the
  124. students, and the easiest for the instructor to grade. However, it
  125. requires that you keep the autograding service running non-stop,
  126. because handouts, grading, and reporting occur continuously for the
  127. duration of the lab. We've made it very easy to run the service, but
  128. some instructors may be uncomfortable with this requirement and will
  129. opt instead for the offline version.
  130. Here are the directions for offering both versions of the lab.
  131. ---
  132. 4.1. Create a Bomb Lab Directory
  133. ---
  134. Identify the generic Linux machine ($SERVER_NAME) where you will
  135. create the Bomb Lab directory (./bomblab) and, if you are offering the
  136. online version, run the autograding service. You'll only need to have
  137. a user account on this machine. You don't need root access.
  138. Each offering of the Bomb Lab starts with a clean new ./bomblab
  139. directory on $SERVER_NAME. For example:
  140. linux> tar xvf bomblab.tar
  141. linux> cd bomblab
  142. linux> make cleanallfiles
  143. ---
  144. 4.2 Configure the Bomb Lab
  145. ---
  146. Configure the Bomb Lab by editing the following file:
  147. ./Bomblab.pm - This is the main configuration file. You will only need
  148. to modify or inspect a few variables in Section 1 of this file. Each
  149. variable is preceded by a descriptive comment. If you are offering the
  150. offline version, you can ignore most of these settings.
  151. If you are offering the online version, you will also need to edit the
  152. following file:
  153. ./src/config.h - This file lists the domain names of the hosts that
  154. notifying bombs are allowed to run on. Make sure you update this
  155. correctly, else you and your students won't be able to run your bombs.
  156. ----
  157. 4.3. Update the Lab Writeup
  158. ---
  159. Once you have updated the configuration files, modify the Latex lab
  160. writeup in ./writeup/bomblab.tex for your environment. Then type the
  161. following in the ./writeup directory:
  162. unix> make clean
  163. unix> make
  164. This will create ps and pdf versions of the writeup
  165. ---
  166. 4.4. Running the Online Bomb Lab
  167. ---
  168. ------
  169. 4.4.1. Short Version
  170. ------
  171. From the ./bomblab directory:
  172. (1) Reset the Bomb Lab from scratch by typing
  173. linux> make cleanallfiles
  174. (2) Start the autograding service by typing
  175. linux> make start
  176. (3) Stop the autograding service by typing
  177. linux> make stop
  178. You can start and stop the autograding service as often as you like
  179. without losing any information. When in doubt "make stop; make start"
  180. will get everything in a stable state.
  181. However, resetting the lab deletes all old bombs, status logs, and the
  182. scoreboard log. Do this only during debugging, or the very first time
  183. you start the lab for your students.
  184. Students request bombs by pointing their browsers at
  185. http://$SERVER_NAME:$REQUESTD_PORT/
  186. Students view the scoreboard by pointing their browsers at
  187. http://$SERVER_NAME:$REQUESTD_PORT/scoreboard
  188. ------
  189. 4.4.2. Long Version
  190. ------
  191. (1) Resetting the Bomb Lab. "make stop" ensures that there are no
  192. servers running. "make cleanallfiles" resets the lab from scratch,
  193. deleting all data specific to a particular instance of the lab, such
  194. as the status log, all bombs created by the request server, and the
  195. scoreboard log. Do this when you're ready for the lab to go "live" to
  196. the students.
  197. Resetting is also useful while you're preparing the lab. Before the
  198. lab goes live, you'll want to request a few bombs for yourself, run
  199. them, defuse a few phases, explode a few phases, and make sure that
  200. the results are displayed properly on the scoreboard. If there is a
  201. problem (say because you forgot to update the list of machines the
  202. bombs are allowed to run in src/config.h) you can fix the
  203. configuration, reset the lab, and then request and run more test
  204. bombs.
  205. CAUTION: If you reset the lab after it's live, you'll lose all your
  206. records of the students bombs and their solutions. You won't be able
  207. to validate the students handins. And your students will have to get
  208. new bombs and start over.
  209. (2) Starting the Bomb Lab. "make start" runs bomblab.pl, the main
  210. daemon that starts and nannies the other programs in the service,
  211. checking their status every few seconds and restarting them if
  212. necessary:
  213. (3) Stopping the Bomb Lab. "make stop" kills all of the running
  214. servers. You can start and stop the autograding service as often as
  215. you like without losing any information. When in doubt "make stop;
  216. make start" will get everything in a stable state.
  217. Request Server: The request server is a simple special-purpose HTTP
  218. server that (1) builds and delivers custom bombs to student browsers
  219. on demand, and (2) displays the current state of the real-time
  220. scoreboard.
  221. A student requests a bomb from the request daemon in two
  222. steps: First, the student points their favorite browser at
  223. http://$SERVER_NAME:$REQUESTD_PORT/
  224. For example, http://foo.cs.cmu.edu:15213/. The request server
  225. responds by sending an HTML form back to the browser. Next, the
  226. student fills in this form with their user name and email address, and
  227. then submits the form. The request server parses the form, builds and
  228. tars up a notifying custom bomb with bombID=n, and delivers the tar
  229. file to the browser. The student then saves the tar file to disk. When
  230. the student untars this file, it creates a directory (./bomb<n>) with
  231. the following four files:
  232. bomb* Notifying custom bomb executable
  233. bomb.c Source code for the main bomb routine
  234. ID Identifies the student associated with this bomb
  235. README Lists bomb number, student, and email address
  236. The request server also creates a directory (bomblab/bombs/bomb<n>)
  237. that contains the following files:
  238. bomb* Custom bomb executable
  239. bomb.c Source code for main routine
  240. bomb-quiet* A quiet version of bomb used for autograding
  241. ID Identifies the user name assigned to this bomb
  242. phases.c C source code for the bomb phases
  243. README Lists bombID, user name, and email address
  244. solution.txt The solution for this bomb
  245. Result Server: Each time a student defuses a phase or explodes their
  246. bomb, the bomb sends an HTTP message (called an autoresult string) to
  247. the result server, which then appends the message to the scoreboard
  248. log. Each message contains a BombID, a phase, and an indication of the
  249. event that occurred. If the event was a defusion, the message also
  250. contains the "defusing string" that the student typed to defuse the
  251. phase.
  252. Report Daemon: The report daemon periodically scans the scoreboard log
  253. and updates the Web scoreboard. For each bomb, it tallies the number
  254. of explosions, the last defused phase, validates each last defused
  255. phase using a quiet copy of the bomb, and computes a score for each
  256. student in a tab delimited text file called "scores.txt." The update
  257. frequency is a configuration variable in Bomblab.pm.
  258. Instructors and students view the scoreboard by pointing their
  259. browsers at:
  260. http://$SERVER_NAME:$REQUESTD_PORT/scoreboard
  261. ------
  262. 4.4.3. Grading the Online Bomb Lab
  263. ------
  264. The online Bomb Lab is self-grading. At any point in time, the
  265. tab-delimited file (./bomblab/scores.txt) contains the most recent
  266. scores for each student. This file is created by the report daemon
  267. each time it generates a new scoreboard.
  268. ------
  269. 4.4.4. Additional Notes on the Online Bomb Lab
  270. ------
  271. * Since the request server and report daemon both need to execute
  272. bombs, you must include $SERVER_NAME in the list of legal machines in
  273. your bomblab/src/config.h file.
  274. * All of the servers and daemons are stateless, so you can stop ("make
  275. stop") and start ("make start") the lab as many times as you like
  276. without any ill effects. If you accidentally kill one of the daemons,
  277. or you modify a daemon, or the daemon dies for some reason, then use
  278. "make stop" to clean up, and then restart with "make start". If your
  279. Linux box crashes or reboots, simply restart the daemons with "make
  280. start".
  281. * Information and error messages from the servers are appended to the
  282. "status log" in bomblab/log-status.txt. Servers run quietly, so they
  283. can be started from initrc scripts at boot time.
  284. * See src/README for more information about the anatomy of bombs and
  285. how they are constructed. You don't need to understand any of this to
  286. offer the lab. It's provided only for completeness.
  287. * Before going live with the students, we like to check everything out
  288. by running some tests. We do this by typing
  289. linux> make cleanallfiles
  290. linux> make start
  291. Then we request a bomb for ourselves by pointing a Web browser at
  292. http://$SERVER_NAME:$REQUESTD_PORT
  293. After saving our bomb to disk, we untar it, copy it to a host in the
  294. approved list in src/config.h, and then explode and defuse it a couple
  295. of times to make sure that the explosions and diffusion are properly
  296. recorded on the scoreboard, which we check at
  297. http://$SERVER_NAME:$REQUESTD_PORT/scoreboard
  298. Once we're satisfied that everything is OK, we stop the lab
  299. linux> make stop
  300. and then go live:
  301. linux> make cleanallfiles
  302. linux> make start
  303. Once we go live, we type "make stop" and "make start" as often as we
  304. need to, but we are careful never to type "make cleanallfiles" again.
  305. ----
  306. 4.5. Running the Offline Bomb Lab
  307. ----
  308. In this version of the lab, you build your own quiet bombs manually
  309. and then hand them out to the students. The students work on defusing
  310. their bombs offline (i.e., independently of any autograding service)
  311. and then handin their solution files to you, each of which you grade
  312. manually.
  313. You can use the makebomb.pl script to build your own bombs
  314. manually. The makebomb.pl script also generates the bomb's solution.
  315. Type "./makebomb.pl -h" to see its arguments.
  316. Option 1: The simplest approach for offering the offline Bomb Lab is
  317. to build a single generic bomb that every student attempts to defuse:
  318. linux> ./makebomb.pl -s ./src -b ./bombs
  319. This will create a generic bomb and some other files in ./bombs/bomb0:
  320. bomb* Generic bomb executable (handout to students)
  321. bomb.c Source code for main routine (handout to students)
  322. bomb-quiet* Ignore this
  323. ID Ignore this
  324. phases.c C source code for the bomb phases
  325. README Ignore this
  326. solution.txt The solution for this bomb
  327. You will handout only two of these files to the students: ./bomb and ./bomb.c
  328. The students will handin their solution files, which you can validate
  329. by feeding to the bomb:
  330. linux> cd bombs/bomb0
  331. linux> ./bomb < student_solution.txt
  332. This option is easy for the instructor, but we don't recommend it
  333. because it is too easy for the students to cheat.
  334. Option 2. The other option for offering an offline lab is to use the
  335. makebomb.pl script to build a unique quiet custom bomb for each
  336. student:
  337. linux> ./makebomb.pl -i <n> -s ./src -b ./bombs -l bomblab -u <email> -v <uid>
  338. This will create a quiet custom bomb in ./bombs/bomb<n> for the
  339. student whose email address is <email> and whose user name is <uid>:
  340. bomb* Custom bomb executable (handout to student)
  341. bomb.c Source code for main routine (handout to student)
  342. bomb-quiet* Ignore this
  343. ID Identifies the student associated with this bomb
  344. phases.c C source code for the bomb phases
  345. README Lists bomb number, student, and email address
  346. solution.txt The solution for this bomb
  347. You will handout four of these files to the student: bomb, bomb.c, ID,
  348. and README.
  349. Each student will hand in their solution file, which you can validate
  350. by hand by running their custom bomb against their solution:
  351. linux> cd ./bombs/bomb<n>
  352. linux> ./bomb < student_n_solution.txt
  353. The source code for the different phase variants is in ./src/phases/.