それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

Windowsのプロダクトキーを確認する(DigitalProductIdをデコード)

追記 at 2010-07-12

WindowsVistaで試したら動かなかったのでへんこう

var ret = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId');
//↓ つぎに変更
var ret = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId4');

なるほど。しっかし、Windowsから簡単に取り出せるとなるとWindowsXPってほんとライセンス盗まれやすいよね。USBメモリウイルスにこのようなプログラム+通信モジュールが仕込まれないことを祈ります。いよいよ明日は、WindowsXpSp2のアップデート停止日、Xpまだ使ってるなら、いちど考え直したほうがいいと思う。セキュリティー的な意味も、ブラウザが古いってことも含めて。

紛失したプロダクトキーをレジストリから取り出す。

Windowsのプロダクトキーってレジストリから簡単に取り出せます。【Windowsのライセンスシール剥がせ】と言ってる人がいたら、少し可笑しく思えてしまう。僕も一年前まではWindowsのライセンスシールを剥がせばプロダクトキーの盗難を防止できると思っていた。

プロダクトキーが解ると。。。

Winnyなどのセキュリティーホールがあるソフトが起動してると危険。任意のプログラムが実行される脆弱性があるとWindowsのライセンスまでごっそり盗まれる。

Windowsのプロダクトキーを取得する.hta

プロダクトキーを紛失したときに使ってください。。。

メモ帳で作れるプロダクトキー表示ソフト
<html><head>
<title>WindowsとOfficeのライセンス確認</title></head>
<body>
<form name="form1">
    <p><input type="button" value="Windowsのライセンスを調査" onClick="show_license('')" /></p>
</form>
<div id="result"></div>
<script type="text/javascript">
//by takuya mori 2009-03-26
//Windowsのシリアルを取得する。
function windows_productkey(){
  WshShell = new ActiveXObject( "WScript.Shell" );
  //ret = WshShell.RegRead('HKCU\\Software\\Microsoft\\Internet Explorer\\Main\\Start Page');
  ret = WshShell.RegRead('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId');
  DigitalProductId = ret.toArray();
  hexPid = DigitalProductId.slice( 52, 67 );
  decodedChars = Array(24);
  digits = Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9");
  for ( var i=1; i<30;i++ ){
    if((i % 6) == 0 ){
      decodedChars.push("-");
     }
    else{
      k=0;
      for ( var j=14; j>=0;j--){
        k = ( k << 8 ) ^ hexPid[j];
        hexPid[j] =  parseInt( k /digits.length );
        k = k % digits.length;
      }
      decodedChars.push(digits[k]);
    }
  }

  WScript.Echo(decodedChars.reverse().join(""));
}
///windows_productkey関数をオブジェクト化して、Officeにも対応させたもの
var ProductKey = function ( ) {
  this.office_regkeys = {
      // 参考 http://d.hatena.ne.jp/frontline/20081222/p1
      "Office XP Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\10.0\\Registration\\{90280411-6000-11D3-8CFE-0050048383C9}",
      "Office XP Professional(English)":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\10.0\\Registration\\{90110409-6000-11D3-8CFE-0050048383C9}",
      "Office 2003 Standard/Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\11.0\\Registration\\{90110411-6000-11D3-8CFE-0150048383C9}",
      "Visio 2003 Standard/Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\11.0\\Registration\\{90510411-6000-11D3-8CFE-0150048383C9}",
      "Office 2007 Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0014-0000-0000-0000000FF1CE}",
      "Office 2007 Professional VL":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0012-0000-0000-0000000FF1CE}",
      "Office 2007 Professional Plus":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0011-0000-0000-0000000FF1CE}",
      "Office 2007 Enterprise":"HKEY_LOCAL_MACHINE\\SOFTWAWRE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0030-0000-0000-0000000FF1CE}",
      "Office 2007 Ultimate":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{91120000-002E-0000-0000-0000000FF1CE}",
      "Visio 2007 Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-0051-0000-0000-0000000FF1CE}",
      "Project 2007 Professional":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\{90120000-003B-0000-0000-0000000FF1CE}",
      "SQL Server 2005":"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\90\\ProductID"
  }
  this.WshShell = new ActiveXObject( "WScript.Shell" );
  this.read_reg = function ( reg_key_name ){
    return  this.WshShell.RegRead(reg_key_name);
  }
  this.decodeDigitalProductId = function( reg_binary_value ){
    reg_binary_value=reg_binary_value.toArray();
    reg_binary_value=reg_binary_value.slice( 52, 67 );
    decodedChars = Array(24);
    digits = Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9");
    for ( var i=1; i<30;i++ ){
      if((i % 6) == 0 ){
        decodedChars.push("-");
       }
      else{
        k=0;
        for ( var j=14; j>=0;j--){
          k = ( k << 8 ) ^ reg_binary_value[j];
          reg_binary_value[j] =  parseInt( k /digits.length );
          k = k % digits.length;
        }
        decodedChars.push(digits[k]);
      }
    }
    var aa = decodedChars.reverse().join('').split("-")
    aa.pop();
    aa.push("*****")
    return aa.join("-");
  }
  this.office = function(){
    var result = [];
    for ( key_name in this.office_regkeys ){
      try{
          var ret = this.read_reg(this.office_regkeys[key_name]+ '\\DigitalProductId');
          result.push( key_name + ":\t" + this.decodeDigitalProductId( ret ));
      }catch(e){
        //
      }
    }
    return result.join("\n");
  }
  this.windows = function (){
    return this.WindowsName() + ":\t" + this.Windows_ProductKey();
  }
  this.Windows_ProductKey = function (){
    var ret = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId');
    return this.decodeDigitalProductId( ret );
  }
  this.WindowsName = function(){
    var name = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName');
    var pack = this.read_reg('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\CSDVersion');
    return name + "("+pack+")";
  }
}


//動作テスト
//windows_productkey()
//var p = new ProductKey();
//WScript.Echo(p.windows());
//WScript.Echo(p.office());

function show_license(){
	var p = new ProductKey();
	var html = "<ul><li>"+p.windows()+"<li>" + p.office().replace("\n", "<br/>\n<li>") + "</ul>"; 
	document.getElementById("result").innerHTML = html;
}

function send_result(){
	var p = new ProductKey();
	var oSkype = new ActiveXObject("Skype4COM.Skype");
	oSkype.Attach();
	oSkype.SendMessage("takuya541226", "\n"+p.windows()+"\n" + p.office());
}
</script>
</body></html>

CD-ROMの自動実行の一部に。。。

Autorunウイルスは本当に怖いと思う。Autorunで上記のスクリプトを実行されると簡単に盗めるってことだよね。

Vistaはすばらしい

VistaUACをオフにするとか神経が逝っちゃってるとしか思えない。UACがあるからこそ、泥棒が上記のようなマルウェアをユーザーに気づかせずに実行することが不可能になるのになぁ。