Pārlūkot izejas kodu

New "-a" option, for slecting a specific attack.

This adds a new command-line option, for selecting the attacks, and improves the
questions enviroment. Specifically,
* Adds a new .pretty_name string to trettify name;
* Adds documentation for structures qa_question_t
* Delegates attacks to a  new function qa_dispose().
Michele Orrù 11 gadi atpakaļ
vecāks
revīzija
8b9e7b4acb

+ 7 - 2
src/cmdline.c

@@ -26,6 +26,7 @@ void usage(void)
 {
   static const char* help_message = "%s usage: %s"
     " [-r HOST:port | -f FILE]"
+    " [-a ATTACK]"
     " \n";
   fprintf(stderr, help_message,
           program_invocation_short_name,
@@ -34,7 +35,7 @@ void usage(void)
 
 void conflicting_args(void)
 {
-  printf("Conflicting fuffa\n");
+  fprintf(stderr, "Conflicting arguments.\n");
   usage();
   exit(EXIT_FAILURE);
 }
@@ -51,10 +52,11 @@ int main(int argc, char** argv)
     {"file", required_argument, NULL, 'f'},
     {0, 0, 0, 0}
   };
-  static const char* short_options = "hr:f:";
+  static const char* short_options = "hr:f:a:";
 
   struct qa_conf conf = {
     .src_type = NONE,
+    .attacks = NULL
   };
 
   while ((opt=getopt_long(argc, argv,
@@ -75,6 +77,9 @@ int main(int argc, char** argv)
       conf.src_type = REMOTE;
       conf.src = optarg;
       break;
+    case 'a':
+      conf.attacks = optarg;
+      break;
     case '?':
     default:
       usage();

+ 3 - 0
src/include/qa/qa.h

@@ -8,11 +8,14 @@ struct qa_conf {
     NONE, LOCAL, REMOTE
   } src_type;
   char *src;
+  char *attacks;
 };
 
 
 int qa_init(const struct qa_conf* args);
 
+void qa_dispose(X509 *crt);
+
 X509* get_local_cert(const char *src);
 
 #endif   /* _QA_H_ */

+ 19 - 6
src/qa.c

@@ -41,8 +41,6 @@ X509* get_local_cert(const char *src)
 int qa_init(const struct qa_conf* conf)
 {
   X509 *crt;
-  RSA *rsa;
-  struct qa_question *q;
 
   /* bind stdout/stderr to a BIO shit to be used externally */
   bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
@@ -62,10 +60,28 @@ int qa_init(const struct qa_conf* conf)
   if (!crt)
     error(EXIT_FAILURE, errno, "oops");
 
+
+  if (!conf->attacks) select_all_questions();
+  else select_question(conf->attacks);
+
+  if (!questions.lh_first) error(EXIT_FAILURE, 0, "No valid question selected.");
+
+  qa_dispose(crt);
+
+  X509_free(crt);
+  return 0;
+}
+
+void qa_dispose(X509 *crt)
+{
+  RSA *rsa;
+  qa_question_t *q;
+
   rsa = X509_get_pubkey(crt)->pkey.rsa;
 
-  register_all_questions();
+  printf("[+] Certificate acquired\n");
   for (q=questions.lh_first; q; q = q->qs.le_next) {
+    printf( "[-] Running: %s\n", q->pretty_name);
     if (q->setup)    q->setup();
     if (q->test)     q->test(crt);
     if (q->ask_rsa)  q->ask_rsa(rsa);
@@ -73,7 +89,4 @@ int qa_init(const struct qa_conf* conf)
     if (q->teardown) q->teardown();
   }
 
-  X509_free(crt);
-
-  return 0;
 }

+ 21 - 6
src/questions/allquestions.c

@@ -1,13 +1,28 @@
+#include <assert.h>
+#include <string.h>
 #include <sys/queue.h>
 
 #include "qa/questions/questions.h"
 
+/**
+ * \brief Select a single question to be used.
+ *
+ */
+void select_question(const char *sq)
+{
+  qa_question_t *q;
 
-#define REGISTER_QUESTION(q)                      \
-  {                                               \
-      extern struct qa_question q;                \
-      LIST_INSERT_HEAD(&questions, &q, qs);       \
-  }
+  select_all_questions();
+  assert(questions.lh_first);
+
+  for (q = questions.lh_first; q && strcmp(q->name, sq); q = questions.lh_first)
+    LIST_REMOVE(q, qs);
+  if (!q) return;
+
+  for (q = q->qs.le_next; q; q = q->qs.le_next)
+    if (strcmp(q->name, sq))
+      LIST_REMOVE(q, qs);
+}
 
 /**
  * /brief Puts registered questions into \ref questions.
@@ -15,7 +30,7 @@
  * Disposes all registered questions into a global linked list, so that future
  * procedures can iterate over all possible tests.
  */
-void register_all_questions(void)
+void select_all_questions(void)
 {
   LIST_INIT(&questions);
 

+ 2 - 1
src/questions/dixon.c

@@ -269,7 +269,8 @@ int dixon_question_ask_rsa(RSA *rsa) {
 }
 
 qa_question_t DixonQuestion = {
-  .name = "Dixon",
+  .name = "dixon",
+  .pretty_name = "Dixon's Factorization",
   .setup = dixon_question_setup,
   .teardown = dixon_question_teardown,
   .test =  NULL,

+ 2 - 1
src/questions/example.c

@@ -40,7 +40,8 @@ int example_question_ask_rsa(RSA *rsa)
 
 
 qa_question_t ExampleQuestion = {
-  .name = "Example Question",
+  .name = "example",
+  .pretty_name = "Example Question",
   .setup = example_question_setup,
   .teardown = example_question_teardown,
   .test = example_question_test,

+ 23 - 8
src/questions/include/questions.h

@@ -5,21 +5,36 @@
 
 #include <openssl/x509.h>
 
-
+/**
+ * A question: name, command-line name, callbacks.
+ */
 typedef struct qa_question {
-  const char* name;
-  int (* setup) (void);
-  int (* teardown) ();
-  int (* test) (X509 *cert);
-  int (* ask_rsa) (RSA *rsa);
-  int (* ask_crt) (X509 *cert);
+  const char* name;            /**< short name - name given as command-line argument */
+  const char* pretty_name;     /**< full name - name used for identifying the question */
+
+  int (* setup) (void);        /**< setup callback - initializes static glabal
+                                  variables.*/
+  int (* teardown) ();         /**< teardown callback - frees static global
+                                  variables */
+  int (* test) (X509 *cert);   /**< test callback - assert the attack can be
+                                  performed over the certificate cert */
+  int (* ask_rsa) (RSA *rsa);  /**< ask_rsa callback - attack the RSA key rsa */
+  int (* ask_crt) (X509 *crt); /**< ask_crt callback - attack the certificate
+                                  crt */
 
   LIST_ENTRY(qa_question) qs;
 } qa_question_t;
 
 LIST_HEAD(listhead, qa_question) questions;
 
-void register_all_questions(void);
+void select_question(const char *);
+void select_all_questions(void);
+
+#define REGISTER_QUESTION(q)                      \
+  {                                               \
+      extern struct qa_question q;                \
+      LIST_INSERT_HEAD(&questions, &q, qs);       \
+  }
 
 
 #endif /* _QA_QUESTIONS_H_ */

+ 2 - 1
src/questions/pollard.c

@@ -112,7 +112,8 @@ int pollard1_question_ask_rsa(RSA *rsa)
 
 
 struct qa_question PollardQuestion = {
-  .name = "Pollard's (p-1) factorization",
+  .name = "pollard1",
+  .pretty_name = "Pollard's (p-1) factorization",
   .setup = pollard1_question_setup,
   .teardown = pollard1_question_teardown,
   .test = NULL,

+ 2 - 1
src/questions/wiener.c

@@ -230,7 +230,8 @@ int wiener_question_ask_rsa(RSA *rsa)
 
 
 qa_question_t WienerQuestion = {
-  .name = "Wiener",
+  .name = "wiener",
+  .pretty_name = "Wiener's Attack",
   .setup = NULL,
   .teardown = NULL,
   .test = NULL,