hashcat 1.2 会话初始化函数

会话初始化是根据用户选择,将各类结构体初始化的过程。

const int rc_session_init = hashcat_session_init (hashcat_ctx, install_folder, \
shared_folder, argc, argv, COMPTIME);

0.hashcat.c文件

有注释真是引起极度舒适,下面挨个看看函数都讲得啥吧。

有些暂时用不到的函数就解释一句行了。

1)如果就例子而言,没特意提到用OpenCL,不需要什么特殊输出,下面这个函数就当它不存在。

//make it a bit more comfortable to use some of the special modes in hashcat
  user_options_session_auto (hashcat_ctx);

2)对event初始化,这个还要结合主函数中hashcat_init (hashcat_ctx, event)来看,给hashcat->event_ctx开了内存空间。

然后在下面的函数中,又填充为0,并且加了thread互斥锁。

// event init (needed for logging so should be first)
  const int rc_event_init = event_ctx_init (hashcat_ctx);

 3)对status初始化,赋值,hwmon也就是温控等方面也初始化了互斥锁。

//status init
  const int rc_status_init = status_ctx_init (hashcat_ctx);

4)先放这,有需要再看。https://github.com/hashcat/hashcat/issues/20

//folder
const int rc_folder_config_init = folder_config_init (hashcat_ctx, install_folder, shared_folder);

 5)同样,用到再说

//pidfile
 const int rc_pidfile_init = pidfile_ctx_init (hashcat_ctx);

6)restore就是复原,read_restore是最重要的函数。

注意一个问题,最后还要重复user_options_getopt

//restore
  const int rc_restore_init = restore_ctx_init (hashcat_ctx, argc, argv);

1.来正文了,不是正文,user_options_preprocess

这个主要是对一些特殊的需求有用的函数

//process user input
 user_options_preprocess (hashcat_ctx);

1)进行stdout_flag检测,stdout_flag初始值就是false的,除非在命令行里指明长指令为--stdout--

 if (user_options->stdout_flag)

2) 一样的不运行

if (user_options->example_hashes  == true
   || user_options->opencl_info     == true
   || user_options->keyspace        == true
   || user_options->speed_only      == true
   || user_options->progress_only   == true)

3) benchmark过,example_hashes过,progress_only过,keyspace过,slow_candidates过,stdout_flag再过……好像终于发现这个函数对于新手不重要了。。。。。。。。。。没有运行的!

2.我不敢保证这是正文 user_options_extra_init 

又有新的结构体了,很重要!

typedef struct user_options_extra
{
  u32 attack_kern;    //ATTACK_KERN_COMBI=1呦

  u32 rule_len_r;
  u32 rule_len_l;

  u32 wordlist_mode;

  char  *hc_hash;   // can be filename or string

  int    hc_workc;  // can be 0 in bf-mode = default mask
  char **hc_workv;

} user_options_extra_t;

1)看看,找到攻击方式了,user_options_extra->attack_kern = ATTACK_KERN_COMBI;偶买噶,选它,选它,选它!

switch (user_options->attack_mode){
    case ATTACK_MODE_STRAIGHT: user_options_extra->attack_kern = ATTACK_KERN_STRAIGHT; break;
    case ATTACK_MODE_COMBI:    user_options_extra->attack_kern = ATTACK_KERN_COMBI;    break;
    case ATTACK_MODE_BF:       user_options_extra->attack_kern = ATTACK_KERN_BF;       break;
    case ATTACK_MODE_HYBRID1:  user_options_extra->attack_kern = ATTACK_KERN_COMBI;    break;
    case ATTACK_MODE_HYBRID2:  user_options_extra->attack_kern = ATTACK_KERN_COMBI;    break;
  }

2)好像没有输入rule_buf。那就都是0吧。

  // rules
  user_options_extra->rule_len_l = (int) strlen (user_options->rule_buf_l);
  user_options_extra->rule_len_r = (int) strlen (user_options->rule_buf_r);

3) hashcat不就是要破一个哈希嘛,hc_hash,就是要破解的哈希。example0.hash的意思懂了~。接着初始化及计算,注意看注释。

  // hc_hash and hc_work*
  user_options_extra->hc_hash  = NULL;
  user_options_extra->hc_workv = NULL;
  user_options_extra->hc_workc = 0;

  //省略前面的if们,因为你们都不true
  else
  {
    user_options_extra->hc_hash  = user_options->hc_argv[0];//根据1.1,指的是example0.hash
    user_options_extra->hc_workc = user_options->hc_argc - 1;//3-1=2
    user_options_extra->hc_workv = user_options->hc_argv + 1;//往后移一个就是掩码了?a?a?a?a
  }

4)单词表的模式。

  // wordlist_mode
  user_options_extra->wordlist_mode = WL_MODE_NONE;//现在是0
  //略
  else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI){
    user_options_extra->wordlist_mode = WL_MODE_FILE;//现在是2
  }
  //略

3.user_options_postprocess

模式是WL_MODE_STDIN时,也就是哈希相关参数一个都没有的时候,才运行下面代码。

if (user_options_extra->wordlist_mode == WL_MODE_STDIN){
    user_options->status = true;
  }

以上确实重要,但是还没到具体攻击算法。

0#还有一些初始化函数

//logfile
const int rc_logfile_init = logfile_init (hashcat_ctx);

// cpu affinity
   const int rc_affinity = set_cpu_affinity (hashcat_ctx);

//prepare seeding for random number generator, required by logfile and rules generator
  setup_seeding (user_options->rp_gen_seed_chgd, user_options->rp_gen_seed);

// To help users a bit
  setup_environment_variables ();//读取设备信息
  setup_umask ();//设置读写权限

//tuning db
/*读入本机能用的设备名称、攻击模式、哈希类型、向量长度、内核加速值、内核循环值,都存在hashcat.hctunez这个文件里*/
  const int rc_tuning_db = tuning_db_init (hashcat_ctx);

//induction directory
/*只有是straight模式时,才动用这个函数*/
  const int rc_induct_ctx_init = induct_ctx_init (hashcat_ctx);

//outfile-check directory
/*在最终的文档中并没有.outfile文件夹,所以应该是没有创建成功*/
  const int rc_outcheck_ctx_init = outcheck_ctx_init (hashcat_ctx);
  const int rc_outfile_init = outfile_init (hashcat_ctx);

  /**
   * potfile init
   * this is only setting path because potfile can be used in read and write mode depending on user options
   * plus it depends on hash_mode, so we continue using it in outer_loop
   *主要存放已经破解过的口令值及对应哈希
   */
  const int rc_potfile_init = potfile_init (hashcat_ctx);

//dictstat init
/*创建.dictstat2文档*/
  const int rc_dictstat_init = dictstat_init (hashcat_ctx);

//loopback init
/*Add new 明文to 导入目录?*/
  const int rc_loopback_init = loopback_init (hashcat_ctx);

//debugfile init
/*输出流定义的位置,如果不指定,就输出到stdout*/
  const int rc_debugfile_init = debugfile_init (hashcat_ctx);

/*Try to detect if all the files we're going to use are accessible in the mode we want them */
  const int rc_user_options_check_files = user_options_check_files (hashcat_ctx);

//opencl和hwmon忽略

虽然确实没有具体运行的函数,但是将参数都传递给了要用的结构体。作用是十分明显的。 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值