码迷,mamicode.com
首页 > 系统相关 > 详细

Cisco_IOU_Crack

时间:2018-12-22 17:26:53      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:error:   The   bin   echo   can   red   strip   cal   ack   

附源码:
#! /usr/bin/python3
print("*********************************************************************")
print("Cisco IOU License Generator - Kal 2011, python port of 2006 C version")
print("Modified to work with python3 by c_d 2014")
import os
import socket
import hashlib
import struct

# get the host id and host name to calculate the hostkey
hostid=os.popen("hostid").read().strip()
hostname = socket.gethostname()
ioukey=int(hostid,16)
for x in hostname:
 ioukey = ioukey + ord(x)
print("hostid=" + hostid +", hostname="+ hostname + ", ioukey=" + hex(ioukey)[2:])

# create the license using md5sum
iouPad1 = b\x4B\x58\x21\x81\x56\x7B\x0D\xF3\x21\x43\x9B\x7E\xAC\x1D\xE6\x8A
iouPad2 = b\x80 + 39*b\0
md5input=iouPad1 + iouPad2 + struct.pack(!L, ioukey) + iouPad1
iouLicense=hashlib.md5(md5input).hexdigest()[:16]

print("\nAdd the following text to ~/.iourc:")
print("[license]\n" + hostname + " = " + iouLicense + ";\n")
print("You can disable the phone home feature with something like:")
print(" echo ‘127.0.0.127 xml.cisco.com‘ >> /etc/hosts\n")

 

问题现象:生成IOU License的时候出现struct.error

#./CiscoIOUkeygen.py
 *********************************************************************
 Cisco IOU License Generator - Kal 2011, python port of 2006 C version
 hostid=a8c0caa0, hostname=192_168_160_202, ioukey=a8c0ce23L
 Traceback (most recent call last):
     File "./crack.py", line 18, in <module>
     md5input=iouPad1 + iouPad2 + struct.pack(!i, ioukey) + iouPad1
 struct.error: integer out of range for i format code

 

分析:可能是由于不同机器算出来的值不一样,转换整数的时候溢出。超出‘i‘的范围那就换类型,用I,l或L可能就行了。

原先第21行是这样的:

  1. md5input=iouPad1 + iouPad2 + struct.pack(‘!i‘, ioukey) + iouPad1

现在将i改成L

  1. md5input=iouPad1 + iouPad2 + struct.pack(‘!L‘, ioukey) + iouPad1

测试成功:
# ./CiscoIOUkeygen.py

  1.     *********************************************************************
  2.     Cisco IOU License Generator - Kal 2011, python port of 2006 C version
  3.     hostid=a8c0caa0, hostname=192_168_160_202, ioukey=a8c0ce23L
  4.     Add the following text to ~/.iourc:
  5.     [license]
  6.     GNS3 = 0c3838fa36b12ed4;
  7.     You can disable the phone home feature with something like:
  8.      echo ‘127.0.0.127 xml.cisco.com‘ >> /etc/hosts


说明:
函数的用法是这样的:struct.pack(format, data)
    The optional first format char indicates byte order, size and alignment:
     @: native order, size & alignment (default)
     =: native order, std. size & alignment
     <: little-endian, std. size & alignment
     >: big-endian, std. size & alignment
     !: same as >
   
    The remaining chars indicate types of args and must match exactly;
    these can be preceded by a decimal repeat count:
     x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;
     h:short; H:unsigned short; i:int; I:unsigned int;
     l:long; L:unsigned long; f:float; d:double.
    Special cases (preceding decimal count indicates length):
     s:string (array of char); p: pascal string (with count byte).
    Special case (only available in native format):
     P:an integer type that is wide enough to hold a pointer.
    Special case (not in native mode unless ‘long long‘ in platform C):
     q:long long; Q:unsigned long long
    Whitespace between formats is ignored.

有时将hostname改短一点也能成功,但不推荐。

Cisco_IOU_Crack

标签:error:   The   bin   echo   can   red   strip   cal   ack   

原文地址:https://www.cnblogs.com/zenosblog/p/10161644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!