[Ugoos X3 and probably a lot of other devices, and even NAS devices] [Solved] Why samba/smb transfer rate is slow despite a gigabit Ethernet port ? - Android Stick & Console AMLogic based Computers

Hello everyone,
For my first thread, I won't ask a question, I will post a solution.
I have recently acquired a second-hand Ugoos X3 device, which is quite a good device.
But I have been really frustrated upon testing it after unboxing it, because despite the fact that this device advertises for the ability of having a Gigabit ethernet port and a builtin samba server, my tests showed a max 11,4 MiB/s instead of rather a 114 MiB/s.
I started to identify the reason, with a vast amount of Googling. After realizing how many people on earth already been through this (mostly unsolved) issue, and after testing the good gigabit-readiness of my Ethernet cable, I dug into the rabbit hole of the system.
I then discovered the root causes, and you won't like it :
- the smbd binary dates from 2005
- the smb.conf is counter-optimized and dates from this 2005 era
See for yourself:
Code:
/data/system/samba_________________ug # ./smbd -V
Version 3.0.20a
Code:
[global]
interfaces = wlan0 eth0 eth1 eth2
min protocol = SMB2
bind interfaces only = yes
workgroup = WORKGROUP
server string = Samba on Android mediacenter
netbios name = mybox
#remote announce = 255.255.255.255
encrypt passwords = yes
security = SHARE
restrict anonymous = 0
load printers = no
printcap name = /dev/null
disable spoolss = yes
deadtime = 5
delete readonly = yes
nt acl support = no
inherit permissions = yes
socket options = IPTOS_LOWDELAY TCP_NODELAY SO_SNDBUF=64000 SO_RCVBUF=64000 SO_KEEPALIVE
local master = no
unix extensions = yes
[internal storage]
vfs objects = fake_perms
comment = mybox /sdcard
path = /sdcard
force user = root
read only = no
writable = yes
guest ok = yes
A lot of directives in this config file are totally deprecated, and the "socket options" is responsible for capping at 11,4 MiB/s.
So after having spent this vast amount of time finding the issue, I took some to patch.
Here's my solution.
0) Root your device
1) Download the Termux compiled package of your device architecture of the "samba" package : https://grimler.se/termux-packages-24/pool/main/s/samba/
2) On your device, replace the smbd binary with the Termux one, at this location : "/data/system/samba_________________ug"
3) Replace the original "smb.conf" (same directory than previous) configuration with this one (which by way the contains security hardening features and support SMBv2 which allows not installing SMBv1 on Windows...)
Code:
[global]
lock dir = /data/local/tmp/lock/
state directory = /data/local/tmp/state/
ncalrpc dir = /data/local/tmp/ncalrpc/
interfaces = wlan0 eth0 eth1 eth2
server min protocol = SMB2
bind interfaces only = yes
workgroup = WORKGROUP
server string = Samba on Android mediacenter
netbios name = mybox
server role = standalone server
security = user
map to guest = Bad Password
usershare allow guests = yes
load printers = no
printcap name = /dev/null
disable spoolss = yes
deadtime = 5
delete readonly = yes
nt acl support = no
inherit permissions = yes
local master = no
disable netbios = yes
smb ports = 445
lm announce = no
multicast dns register = no
[internal storage]
vfs objects = fake_perms
comment = mybox /sdcard
path = /sdcard
force user = root
read only = no
writable = yes
guest ok = yes
4) Edit the "smbd" binary calling line in the "samba-rc" launching script, with this one
Code:
$PRE/smbd -D -s /data/system/samba_________________ug/smb.conf
Reboot your device, you now have a best-of-breed samba server and configuration.
A simple but heartful message to Ugoos: update the packages you use in your image ! We need more up-to-date binaries and configuration from your products ! Provide firmwares that does not require to make people do insecure stuff such as installing SMBv1 client on their client !
I am really grateful to these resources which helped a lot:
- https://lafibre.info/nas/perfs-moisies-avec-samba/ (sorry, in french, use google translate)
- https://serverfault.com/questions/470650/samba-configuration-for-public-shares/700449#700449
- https://blog.hiebl.cc/posts/why-your-samba-config-does-not-work/

Hello. According to your instructions with file replacement and line editing, the server becomes inoperable. The server activation checkbox is not activated in the ugoos settings. Please describe the actions in more detail or upload files for replacement.

Hello @Nereal-NeSkill,
As of step 1), try to perform a "pkg install samba" first with Termux.
Then, can you perform a "./samba-rc start" and paste here the output ?

Was a bit skeptical replacing daemon but It works great!

Related

[EXPERIMENTAL] [PHP SCRIPT] WIFI-MAC Spoofer v1.1

Hi.
I wasn't too sure, if I should post this into the development area, I think it fits more into general.
Introduction
According to this thread, I tried to write a little script which lets one spoof his wi-fi MAC address unindependently from any adb shell or usb connection. It's very experimental and might not work that properly. If I try it at home, my router somehow shuts down any incoming wi-fi connection in the whole network and turns the internet off. :/ But the script itself actually SEEMS to change the MAC address (according to what the wi-fi settings say).
I am not responsible for any damage to your phone. However, you can reset the changed MAC address anyway, if something bad happens.
Please note, that you are only allowed to use this script in those networks where you have the permission to do so. Especially the use of the "MAC takeover" function might be illegal in different networks.
Requirements
You will need SL4A (Android Scripting Environment) and PFA (PHP for Android). Check out: http://www.phpforandroid.net/#requirements
The script
PHP:
<?php
// config: config-file and tmp-file
$cnf = "/etc/wl/nvram.txt";
$tmp = "/sdcard/nvram-tmp.txt";
// this is my very dirty solution to replace the actual config file with a new edited one. root needed. might not work everywhere.
$cmd = 'su -c "mount -o rw,remount -t yaffs2 /dev/block/mtdblock4 /system; mv -f \"'.$tmp.'\" \"'.$cnf.'\"; chmod 644 \"'.$cnf.'\"; mount -o ro,remount -t yaffs2 /dev/block/mtdblock4 /system"';
// access android api
require_once("Android.php");
$droid = new Android();
// get config file src
$src = file_get_contents($cnf);
// check, if mac address was already spoofed before
preg_match("|macaddr=([a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2})|i", $src, $res);
$spoofed = false;
$macaddr = "13:57:9B:DF:13:37";
if(isset($res[1]))
{
$spoofed = true;
$macaddr = $res[1];
}
// pre-configurations
$title = "LG-OO-P500 MAC Spoofer";
$action = "start";
// main loop for actions
while(true)
{
switch($action)
{
// start
case "start":
$msg = "Your MAC address is currently set on default.";
// currently spoofed mac address?
if($spoofed)
{
$msg = "Your currently spoofed MAC address is: ".$macaddr;
}
$droid->makeToast($msg);
// create dialog
$droid->dialogCreateAlert($title);
$droid->dialogSetItems(array("Change MAC address", "MAC takeover", "Reset MAC address", "Exit"));
$droid->dialogShow();
// determine next action
$res = $droid->dialogGetResponse();
$actions = array("spoof", "scan", "reset", "exit");
$action = $actions[$res["result"]->item];
$droid->dialogDismiss();
break;
// spoof and reset action
case "spoof": case "scan": case "reset":
// get user input for new mac addr
switch($action)
{
case "spoof":
while(true)
{
$res = $droid->dialogGetInput($title, "Insert new MAC address", $macaddr);
$macaddr = strtoupper($res["result"]);
if(preg_match("|[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}|i", $macaddr))
{
break;
}
$droid->makeToast("Invalid MAC address. (example: 00:00:00:00:00:00 to FF:FF:FF:FF:FF:FF)");
}
$rpl = "macaddr=".$macaddr;
break;
case "scan":
$droid->dialogCreateSpinnerProgress("Now scanning network...");
// scan for MACs and filter ip and MAC addresses from the output
exec("arp -a", $out);
preg_match_all("|\(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\) at ([a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2})|i", strtoupper(implode("\r\n", $out)), $res);
$droid->dialogDismiss();
// create new array
$arr = array();
for($i = 0; $i != count($res[1]); $i++)
{
$arr["list"][] = $res[1][$i]."\n=> ".$res[2][$i];
$arr["ip"][] = $res[1][$i];
$arr["mac"][] = $res[2][$i];
}
$droid->dialogCreateAlert("Found ".count($arr)." individuals... please choose:");
$droid->dialogSetItems($arr["list"]);
$droid->dialogShow();
$res = $droid->dialogGetResponse();
$rpl = "macaddr=".$arr["mac"][$res["result"]->item];
break;
case "reset": default:
$rpl = null;
break;
}
// edit src
($spoofed || empty($rpl)) ? $src = rtrim(preg_replace("|macaddr=.*|i", $rpl, $src)) : $src = rtrim($src)."\n".$rpl;
// disable wifi
$droid->toggleWifiState(false);
// save tmp file
$h = fopen($tmp, "w");
fwrite($h, $src);
fclose($h);
// overwrite with root privileges
exec($cmd);
$droid->makeToast("Operation complete.");
$action = "exit";
break;
// exit
case "exit":
// enable wlan and exit
$droid->toggleWifiState(true);
$droid->exit();
exit();
break;
}
}
I am really not sure, if it is going to work for you. I tested it under devoid #forever (CM7, 2.3.4). Maybe other ROMs and other smartphones are going to behave different. And to be honest, for me it didn't work that good either until now.
If you are having trouble, you can also try to reboot after spoofing.
Have fun trying.
Is this all this about adding macaddr in nvram.txt as we had this discussion earlier.
Nice work.
Sent from my LG-P500 using XDA Premium App
I added another very experimental function which I named "MAC takeover". It allows the user to scan the network for all connected MAC addresses and afterwards display and finally spoof one of those addresses.
The whole script might be buggy, so tell me if something doesn't work properly.
Please note, that you are only allowed to use this script in those networks where you have the permission to do so. Especially the use of the "MAC takeover" function might be illegal in different networks.
See the changes above in the source code.
Is this all this about adding macaddr in nvram.txt as we had this discussion earlier.
Click to expand...
Click to collapse
Yup, but it makes things a lot easier, because you just need your phone to change the MAC address. Additionally it has something like an interface.
I have a bash script somewhere doing the same (except for takeover... nasty boy ). Will post it when I find it. Should be a hell lot easier to use (just bash, no weird stuff needed.)
This is actually quite easy as well, you just need PHP installed on android. However, I'm also very interested in that bash script, please share!

[Q] How select preferred network operators automatically?

Hallo,
I want to select preferred network operators automatically from device.
After I search for it, I found following:
Code:
final int EVENT_AUTO_SELECT_DONE = 300;
Message msg = mHandler.obtainMessage(EVENT_AUTO_SELECT_DONE);
phone.setNetworkSelectionModeAutomatic(msg);
So I need an instance of class "Phone". I tried this:
Code:
String phoneFactoryName = "com.android.internal.telephony.PhoneFactory";
String phoneName = "com.android.internal.telephony.Phone";
Class phoneFactoryClass = Class.forName(phoneFactoryName);
Class phoneClass = Class.forName(phoneName);
Method getDefaultPhone = phoneFactoryClass.getMethod("getDefaultPhone");
Object phoneObject = getDefaultPhone.invoke(null);
But the method "getDefaultPhone" can only called by looper.
Next I tried this:
Code:
String phoneAppName = "com.android.phone.PhoneApp";
Class phoneAppClass = Class.forName(phoneAppName);
Method getInstanceMethod = phoneAppClass.getMethod("getInstance");
Object phoneObject = getInstanceMethod.invoke(null);
But I get a ClassNotFoundException.
Can anybody help me, please?
sorry ,i can't help you
Yes it can be instantiated. But you have to overcome a couple of hurdles:
In your AndroidManifest.xml set
Code:
android:sharedUserId="android.uid.phone"
within the manifest-Tag. This is required to prevent a SecurityException from being thrown when protected Intents are sent by the methods you may invoke (like android.intent.action.SIM_STATE_CHANGED).
Set
Code:
android:process="com.android.phone"
in your application-Tag. This is required to allow the invocation of getDefaultPhone / makeDefaultPhone.
To do all this your app must be signed with the system signature key.

[Q] What the correct way to read from thumb_image column on messages table (Whatsapp)

Hi all,
I build a software for myself that read from Whatsapp db (that stored on my android device)..
I trying to read from thumb_image column but cannot find the correct way ...
I write this software on c# language... and the code for read its column as follows:
//thumbImage is the value that stored in thumb_image column.
byte[] encodedbytes = System.Text.Encoding.Unicode.GetBytes(thumbImage);
string encoded = System.Convert.ToBase64String(encodedbytes);
byte[] utf8Decoded = System.Text.Encoding.UTF8.GetBytes(encoded);
File.WriteAllBytes("Images\\" + mdeiaName, utf8Decoded);
but it's not working, so i trying to use IronPython as following:
string pythonScript = @"import base64
class DecryptString(object):
def Decrypt(self, str):
return base64.b64encode(str).decode(""utf-8"")";
ScriptEngine engine = Python.CreateEngine();
ScriptSource source = engine.CreateScriptSourceFromString(pythonScript);
ScriptScope scope = engine.CreateScope();
source.Execute(scope);
dynamic DecryptString = scope.GetVariable("DecryptString");
dynamic decryptString = DecryptString();
var result = decryptString.Decrypt(thumbImage);
File.WriteAllText("Images\\" + mdeiaName, result);
but without success...
Can somebody help me?

Raspberry GPIO email script

Hi,
I made a simple script that sends me an email when the raspberry detects a rising signal on a gpio input
Between the switch and the gpio i have mounted a resistor (1K ohm all connections are soldered) to prevent the gpio from flaoting
Script works well but when it is up and running for about 15min the RPI detects a rising signal?
Can someone help me out?
greets kawa
Script:
--------------------------------------------------------------------------
import smtplib
import time
def sendemail(from_addr, to_addr_list, cc_addr_list,
subject, message,
login, password,
smtpserver='smtp.gmail.com:587'):
header = 'From: %s\n' % from_addr
header += 'To: %s\n' % ','.join(to_addr_list)
header += 'Cc: %s\n' % ','.join(cc_addr_list)
header += 'Subject: %s\n\n' % subject
message = header + message
server = smtplib.SMTP(smtpserver)
server.starttls()
server.login(login,password)
problems = server.sendmail(from_addr, to_addr_list, message)
server.quit()
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.OUT, initial=False) #Siren pin setup
try:
GPIO.wait_for_edge(23, GPIO.RISING)
print "\nRising edge ALARM"
sendemail(from_addr = '@gmail.com',
to_addr_list = ['@gmail.coml'],
cc_addr_list = [''],
subject = 'ALARM',
message = 'alarm',
login = '@gmail.com',
password = '****')
GPIutput(24, True)
time.sleep(5)
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
GPIO.cleanup() # clean up GPIO on normal exit

[Q] Want a tool to backup /phone & /sdcard entirely, over wifi

Hi all,
Anyone know of a tool to do this?
I know what Titanium backup is and what it's for, I'm after a simple data copying tool for the ENTIRE contents of the SD Card and the phone itself just to a network drive.
I can do this manually now, by plugging in the phone and dragging and dropping the files. I'd prefer something which does it over wifi to an SMB share.
I'd assume such a tool already exists, scheduling would be nice, options to enforce only when plugged in to power too (since it'll take half the night while it's charging)
Any tips?
Hi
wizzbang3 said:
Hi all,
Anyone know of a tool to do this?
I know what Titanium backup is and what it's for, I'm after a simple data copying tool for the ENTIRE contents of the SD Card and the phone itself just to a network drive.
I can do this manually now, by plugging in the phone and dragging and dropping the files. I'd prefer something which does it over wifi to an SMB share.
I'd assume such a tool already exists, scheduling would be nice, options to enforce only when plugged in to power too (since it'll take half the night while it's charging)
Any tips?
Click to expand...
Click to collapse
Yes I got one. Helium Backup. You can upload your files to your dropbox account, that's over wifi
I don't want to send it "to the cloud" just a local FTP / SMB server. It's near 80gb of data.
I do it the other way around. I use a Samba Server on the phone and run a sync tool on my PC to sync phone to backup directories on my PC.
On the phone I use [APP][2.0.1+][Root] Samba Filesharing Server for Android [Play & Dev builds].
On the PC I use Syncovery – file synchronization and backup.
You may also use GoodSync: File Sync & Backup Software. It has its own server to run on the phone and is somewhat easier to setup.
Sergio Barbosa said:
I do it the other way around. I use a Samba Server on the phone and run a sync tool on my PC to sync phone to backup directories on my PC.
On the phone I use [APP][2.0.1+][Root] Samba Filesharing Server for Android [Play & Dev builds].
On the PC I use Syncovery – file synchronization and backup.
You may also use GoodSync: File Sync & Backup Software. It has its own server to run on the phone and is somewhat easier to setup.
Click to expand...
Click to collapse
Thanks man, I'll give it a shot - it'll be a drain on the phone overnight but as long as it's charging - I'll have a nice regular sync of my data.
If you decide to go with the Syncovery/Samba Filesharing here is my smb.conf file with mappings for internal storage, sdcard, root and data.
The file must be placed in data/data/com.funkyfresh.samba/files.Just change the workgroup, netbios name and remote announce to suit your needs.
You must use the dev-version of Samba - download from the OP. In settings tick the "Don´t rewrite smb.conf".
Code:
#
#
#
[global]
interfaces = wlan0
bind interfaces only = yes
workgroup = WORKGROUP
server string = Samba on Android
netbios name = SERGIO-SGN3T
remote announce = 255.255.255.0
encrypt passwords = yes
security = USER
restrict anonymous = 1
load printers = no
printcap name = /dev/null
disable spoolss = yes
deadtime = 5
delete readonly = yes
nt acl support = no
inherit permissions = yes
socket options = SO_SNDBUF=16384 SO_RCVBUF=16384
unix extensions = no
[IntSD]
vfs objects = fake_perms
path = /storage/sdcard0
force user = root
read only = no
writable = yes
guest ok = no
[ExtSD]
vfs objects = fake_perms
path = /storage/sdcard1
force user = root
read only = no
writable = yes
guest ok = no
[root]
vfs objects = fake_perms
path = /
force user = root
read only = no
writable = yes
guest ok = no
[data]
vfs objects = fake_perms
path = /data/data
force user = root
read only = no
writable = yes
guest ok = no
Actually, it just occurred to me, I am running a linux based NAS (well BSD) so it would be really better if I could just "push to" an SMB or FTP share, since my PC's are often off at night Any ideas?
For anyone curious, I ended up using FolderSync - it's well supported and works perfectly. I back up my phone once every other night with TitaniumBackup, then the every other night FolderSync backs up the ENTIRE phone and the ENTIRE SD card over wifi, if plugged in to power.
Sure it's 80gb of data but I can lose my phone and get everything back, perfectly.

Categories

Resources