保护Android Web服务

问题描述:

我正在开发一个Android应用程序,它向我在PHP中创建的Web服务发出请求。我从Android应用程序获取数据的方式是静态地在代码后面传递URL。该代码中的该URL对用户不可见。有没有可能让我的网址泄露给用户,并有可能允许该用户侵入我的网络服务?保护Android Web服务

我在*中提到了应该使用字符串资源静态保存我的URL的解决方案。但是我在这里也遇到了一个问题,那就是如果根源为Android的资源可以在文件管理器中打开。

如果任何人都可以给我一个提示开始于:

  1. 通过Web服务调用PHP内部函数。

    公共职能getStudents(){// 守则让学生JSON }

    通话功能像http://mysite.com/getStudents()

  2. 隐藏调用Android的Web服务的URL。

+4

在一定程度上的URL将被揭示这是一笔大交易,你应该在你的网络服务中加入一些安全措施...... –

+0

某人如何才能通过拥有该网址侵入你的网络服务? – Supericy

+0

@Supericy我不确定是否诚实,Im正在考虑如果您的Web服务中的URL和方法名称对某人可见,那么这可能是一种可能性。我可能会使用RSenApps的建议。 –

如果我理解正确的话,你希望用户(谁的应用任何用户),看看在你的应用中的一些数据,但不能够直接下载。这意味着您同时希望用户访问数据并且无法访问数据,这显然是不可能的。内容产业已经尝试并失败了无数的DRM计划。你可以做什么(以及DRM做什么)会让数据变得更加恼人。

用户可以通过嗅探(拦截)流量来获取URL。为了防止这种情况发生,您应该使用SSL,并且包含额外的检查来限制将被允许的SSL证书。这将阻止用户在手机上安装自己的CA,然后使用MitM工具获取URL。

然后,您需要隐藏URL /键/无论您使用哪种方式来区分您的应用程序和恶意用户,并尽可能使用浏览器尽可能深入您的应用程序。当然可以将其隐藏在代码中,并确保使用ProGuard使其更难阅读。

此外,使用自定义用户代理,自定义HTTP头和其他有趣的东西,检查它的服务器端返回一个通用的错误消息,以便攻击者不知道你是如何发现他没有使用你的应用程序,隐藏将这些全部添加到您的应用中的代码。所以如果是真的(有些东西可以使用静态的呼叫设置,这样你就可以把它隐藏几乎任何地方。)

public class WebServis extends AppCompatActivity { 
    ProgressDialog pDialog; 
    // Web Servisimizdeki Namspace alanı 
    private final String _Namspace  = "http://tempuri.org/"; 
    // Web Servimizdeki Method ismi 
    private final String _MethodName = "methodname"; 
    // Namspace ile Method isminin birleşimi 
    private final String _Action  = "http://tempuri.org/"+_MethodName; 
    // Web Servisimizin Adresi 
    private final String _Url   = "http://"ip&or&domain"/WebService/Service.asmx"; 
    private String _ResultValue   = ""; 
    Context context; 
    EditText _birinci_sayi,_ikinci_sayi; 
    String a,b; 
    String TAG = "Response"; 
    String resultString; 
    Object object=null; 
    //priv JSONArrayAdapter getListView; 
    private ListView lv; 
    ArrayList contactList; 
    Button _btn_topla; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_web_servis); 
     // Topla butonumuzu tanımlıyoruz. 
     _btn_topla=(Button)findViewById(R.id.button); 
     // Yukarıda tanımladığımız _btn_topla butonuna tıklama olayını tanımlıyoruz. 
     lv= (ListView)findViewById(R.id.listView); 
     _btn_topla.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       //Hazırladığımız AsyncTask'ımızı çalıştırıyoruz.. 

       AsyncCallWS task = new AsyncCallWS(); 
       task.execute(); 
      } 
     }); 
    } 
    // Arkaplanda webservis işlemlerimizi yaptığımız yer. 
    // AsyncTask sınıfımızdan _WebServiceAsyncTask türetiyoruz.. 
    private class AsyncCallWS extends AsyncTask<Void, Void, Void> { 
     @Override 
     protected void onPreExecute() { 
      Log.i(TAG, "onPreExecute"); 
     } 
     @Override 
     protected Void doInBackground(Void... params) { 
      Log.i(TAG, "doInBackground"); 
      calculate(); 
      HashMap<String, String> contact = new HashMap<>(); 
      showData(resultString); 
      return null; 
     } 
     @Override 
     protected void onPostExecute(Void result) { 
      super.onPostExecute(result); 
      Log.i(TAG, "onPostExecute"+ resultString); 
      Log.i(TAG, "Step 9"); 
      try { 
       ListAdapter adapter = new SimpleAdapter(
         WebServis.this, contactList, 
         R.layout.list_order, new String[]{"name", "email", 
         "adres"}, new int[]{R.id.Name, 
         R.id.Email, R.id.Adres}); 
       Log.i(TAG, "Step 10"); 
       lv.setAdapter(adapter); 
       Log.i(TAG, "Step 11"); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(),"Hata" + e.toString(),Toast.LENGTH_SHORT).show(); 
       e.printStackTrace(); 
      } 
     } 
    } 

    public void calculate() { 
     String SOAP_ACTION = _Action; 
     String METHOD_NAME = _MethodName; 
     String NAMESPACE = _Namspace; 
     String URL = _Url; 
     try { 
      //PropertyInfo propertyInfo=new PropertyInfo(); 
      SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME); 
      Request.addProperty("TABLENAME","USER_TBL"); 
      Request.addProperty("COLUMNS","USERID,NAME,PASS,EPOSTA,ADRESS"); 
      Request.addProperty("WHERECRTR",""); 
      Request.addProperty("TOP",""); 
      Request.addProperty("COLUMN",""); 
      SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      soapEnvelope.dotNet = true; 
      //soapEnvelope.headerOut = security; // this is an Element[] created before 
      soapEnvelope.setOutputSoapObject(Request); 
      HttpTransportSE transport = new HttpTransportSE(URL); 
      transport.debug=true; 
      transport.call(SOAP_ACTION, soapEnvelope); 
      SoapPrimitive response = (SoapPrimitive) soapEnvelope.getResponse(); 
      //resultString1 = (SoapPrimitive) soapEnvelope.getResponse(); 

      resultString =response.toString(); 
      Log.i(TAG, "Result Celsius: " + resultString); 
     } catch (Exception ex) { 
      // Log.e(TAG, "Error: " + ex.getMessage()); 
     } 
    } 
    private void showData(String json) { 
     String jsonStr = json; 
     Log.e(TAG, "Response from json: " + jsonStr); 
     if (jsonStr != null) { 
      try { 
       JSONObject jsonObj = new JSONObject(jsonStr); 
       // Getting JSON Array node 
       JSONArray contacts = jsonObj.getJSONArray("USER_TBL"); 
       // looping through All Contacts 
       contactList = new ArrayList<HashMap<String, String>>(); 
       for (int i = 0; i < contacts.length(); i++) { 
        JSONObject c = contacts.getJSONObject(i); 
        String id = c.getString("USERID"); 
        String name = c.getString("NAME"); 
        String email = c.getString("EPOSTA"); 
        String address = c.getString("ADRESS"); 
        String pass = c.getString("PASS"); 
        HashMap<String, String> contact = new HashMap<String, String>(); 
        contact.put("id", id); 
        contact.put("name", name); 
        contact.put("email", email); 
        contact.put("adres", address); 
        contact.put("pass", pass); 
        //contact.put("mobile", mobile); 
        // adding contact to contact list 
        contactList.add(contact); 
       } 
      } catch (final JSONException e) { 
       Log.e(TAG, "Json parsing error: " + e.getMessage()); 
       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 
         Toast.makeText(getApplicationContext(), 
           "Json parsing error: " + e.getMessage(), 
           Toast.LENGTH_LONG) 
           .show(); 
        } 
       }); 
      } 
     } else { 
      Log.e(TAG, "Couldn't get json from server."); 
      runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 
        Toast.makeText(getApplicationContext(), 
          "Couldn't get json from server. Check LogCat for possible errors!", 
          Toast.LENGTH_LONG) 
          .show(); 
       } 
      }); 
     } 
    } 
} 

ASP.net

public string xLxS(string TABLENAME, string COLUMNS, string WHERECRTR, string TOP, string COLUMN) 
     { 
      string sonuc = ""; 
      DT = dataclass.SELECTSQL(TABLENAME, COLUMNS,TOP, WHERECRTR, ""); 
      if (DT.Rows.Count == 1) 
      { 
       if (COLUMN != "") 
       { 
        sonuc = DataTableToJsonObj(DT,TABLENAME); 
       } 
       else 
       { 
        sonuc = DT.Rows[0][COLUMN].ToString(); 
       } 
      } 
      else if(DT.Rows.Count > 1) 
      { 
       sonuc = DataTableToJsonObj(DT,TABLENAME); 
      } 
      return sonuc.ToString(); 
     }