分类目录归档:Dev

在Linux下重置Windows密码

前置条件

OS环境为Ubuntu

软件依赖

apt-get update && apt-get install -y ntfs-3g chntpw

操作步骤

1. 假设windows分区为sda2

$> mkdir -p /mnt/win && mount /dev/sda2 /mnt/win

2. 进入config目录

$> cd /mnt/win/Windows/System32/config

3. 查看SAM信息

$> chntpw -l SAM
chntpw version 0.99.6 080526 (sixtyfour), (c) Petter N Hagen
Hive <SAM> name (from header): <\SystemRoot\System32\Config\SAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 666c <lf>
Page at 0x8000 is not 'hbin', assuming file contains garbage at end
File size 262144 [40000] bytes, containing 7 pages (+ 1 headerpage)
Used for data: 299/26944 blocks/bytes, unused: 19/1504 blocks/bytes.

* SAM policy limits:
Failed logins before lockout is: 0
Minimum password length        : 0
Password history count         : 0
| RID -|---------- Username ------------| Admin? |- Lock? --|
| 01f4 | Administrator                  | ADMIN  | dis/lock |
| 01f5 | Guest                          |        | dis/lock |

4. 解锁Administrator

$> chntpw -u Administrator SAM
chntpw version 0.99.6 080526 (sixtyfour), (c) Petter N Hagen
Hive <SAM> name (from header): <\SystemRoot\System32\Config\SAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 666c <lf>
Page at 0x8000 is not 'hbin', assuming file contains garbage at end
File size 262144 [40000] bytes, containing 7 pages (+ 1 headerpage)
Used for data: 299/26944 blocks/bytes, unused: 19/1504 blocks/bytes.

* SAM policy limits:
Failed logins before lockout is: 0
Minimum password length        : 0
Password history count         : 0
| RID -|---------- Username ------------| Admin? |- Lock? --|
| 01f4 | Administrator                  | ADMIN  | dis/lock |
| 01f5 | Guest                          |        | dis/lock |

---------------------> SYSKEY CHECK <-----------------------
SYSTEM   SecureBoot            : -1 -> Not Set (not installed, good!)
SAM      Account\F             : 0 -> off
SECURITY PolSecretEncryptionKey: -1 -> Not Set (OK if this is NT4)
Syskey not installed!

RID     : 0500 [01f4]
Username: Administrator
fullname:
comment : Built-in account for administering the computer/domain
homedir :

User is member of 1 groups:
00000220 = Administrators (which has 1 members)

Account bits: 0x0010 =
[ ] Disabled        | [ ] Homedir req.    | [ ] Passwd not req. |
[ ] Temp. duplicate | [X] Normal account  | [ ] NMS account     |
[ ] Domain trust ac | [ ] Wks trust act.  | [ ] Srv trust act   |
[ ] Pwd don't expir | [ ] Auto lockout    | [ ] (unknown 0x08)  |
[ ] (unknown 0x10)  | [ ] (unknown 0x20)  | [ ] (unknown 0x40)  |

Failed login count: 25, while max tries is: 0
Total  login count: 37

- - - - User Edit Menu:
 1 - Clear (blank) user password
 2 - Edit (set new) user password (careful with this on XP or Vista)
 3 - Promote user (make user an administrator)
 4 - Unlock and enable user account [probably locked now]
 q - Quit editing user, back to user select
Select: [q] > 4

Hives that have changed:
 #  Name
 0  <SAM>
Write hive files? (y/n) [n] : y
 0  <SAM> - OK

Python pip SSL 警告

pip使用requests时出现警告信息

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

解决方法:

Step 0x0

CentOS:
yum install python-devel libffi-devel openssl-devel
Ubuntu:
apt-get install python-dev libffi-dev libssl-dev

Step 0x1

pip install pyopenssl ndg-httpsclient pyasn1

Vim技巧

vim全局配置文件

/etc/vim/vimrc

光标回到上次编辑位置

au BufReadPost * if line("'"") > 0|if line("'"") <= line("$")|exe("norm '"")|else|exe "norm $"|endif|endif

复制

从本行开始复制10行
y10y

从n行复制到m行
:n,my
:10,15y

以root权限保存

:w !sudo tee %

GDB简介

GDB常见用法

·设置断点
(gdb) break main
(gdb) break main.cpp:12 if i > 12
条件断点

格式: break 函数名
break 行号
break 文件名:行号
break 文件名:函数名
break +偏移量
break -偏移量
break *地址

·查看断点
(gdb) info break

·删除断点
(gdb) delete N
删除N号断点

·运行
(gdb) run

·显示所有栈帧
(gdb) backtrace
显示开头的栈帧
(gdb) bt N

·显示变量
(gdb) p argv
$1 = (char **) 0xb9d23f
(gdb) p argv[0]
$2 = (char *) “/bin/test.exec”

·显示寄存器
(gdb) info reg
(gdb) p $pc

·单步执行
(gdb) next

·继续执行
(gdb) continue
(gdb) continue N
继续几次,continue 5表示前面5次不会停下,第六次进入此断点时会停下。

·监视点
(gdb) watch <表达式>
<表达式>发生变化时真挺运行,表达式的意思指的是常量或变量
(gdb) awatch <表达式> 被访问时中断
(gdb) rwatch <表达式>

·删除监视点
(gdb) delete N 删除N号监视点 ·改变变量的值
(gdb) p i
$0 = 1
(gdb) set varible i = 0
(gdb) p i
$1 = 0
设置变量i的值
// end

C++封装调用lua任意个数参数的函数

lua 函数调用的c++封装。 借用了模板,以及同名函数的语言特性实现自动匹配lua函数任意个数参数。

#define MAKE_PUSHER(_type, _functionname) \
void push(lua_State *l, _type data){ \
    _functionname(l, data );\
}

MAKE_PUSHER(int, lua_pushinteger)
MAKE_PUSHER(bool, lua_pushboolean)
MAKE_PUSHER(float, lua_pushnumber)
MAKE_PUSHER(double, lua_pushnumber)

// 无参数
int call(lua_State* l, const char* functionname){
    cout << "====>" << __LINE__ << " value:" << functionname <<endl;
    lua_getglobal (l, functionname);
    if ( !lua_isfunction(l, -1)){
        fprintf(stderr, " %s not a function", functionname);
        return 0;
    }
    int rs = lua_pcall(l, 0, 1, 0);
    // global function must return a integer
    if ( !lua_isnumber (l, -1)){
        //DLogLuaError( "Global function must return integer" );
        lua_pop( l, 1);
        return rs;
    }
    rs = lua_tointeger( l, -1);
    lua_pop( l, 1);

    return rs;
}

// 1个参数
template <typename T>
int call(lua_State* l, const char* functionname, T t){
    auto value = t;
    cout << "====>" << __LINE__ << " value:" << value <<endl;
    lua_getglobal (l, functionname);
    if ( !lua_isfunction(l, -1)){
        fprintf(stderr, " %s not a function", functionname);
        return 0;
    }
    push(l, value);
    int rs = lua_pcall(l, 1, 1, 0);
    // global function must return a integer
    if ( !lua_isnumber (l, -1)){
        //DLogLuaError( "Global function must return integer" );
        lua_pop( l, 1);
        return rs;
    }
    rs = lua_tointeger( l, -1);
    lua_pop( l, 1);

    return rs;
}

// 2个参数以上
template <typename T>
int call(lua_State* l, const int nArgs, T t){
    auto value = t;
    cout << "====>" << __LINE__ << " value:" << value <<endl;
    push(l, value);
    int rs = lua_pcall(l, nArgs, 1, 0);
    // global function must return a integer
    if ( !lua_isnumber (l, -1)){
        //DLogLuaError( "Global function must return integer" );
        lua_pop( l, 1);
        return rs;
    }
    rs = lua_tointeger( l, -1);
    lua_pop( l, 1);

    return rs;
}

template <typename T, typename U, typename ...Args>
int call(lua_State* l,const int nArgs, T&& t, U&& u,Args&&... args){
    auto value = t;
    cout << "====>" << __LINE__ << " value:" << value <<endl;
    push(l, value);
    int rs = call(l, nArgs, u, args... );
    return rs;
}

template <typename Header, typename Sencond, typename ...Others>
int call(lua_State* l,  const char* functionname, const int nArgs,
        Header&& t, Sencond&& u, Others&&... others){
    auto value = t;
    cout << "====>" << __LINE__ << " value:" << value <<endl;
    lua_getglobal (l, functionname);
    if ( !lua_isfunction(l, -1)){
        fprintf(stderr, " %s not a function", functionname);
        return 0;
    }
    push(l, value);
    int rs = call(l, nArgs, u, others... );
    return rs;
}
// end 2个参数以上