Compare commits

...

67 Commits

Author SHA1 Message Date
Colin Kuebler a34b2c9186
Merge pull request #1137 from ct-Open-Source/development
Release v2.4.6
2024-09-06 11:57:41 -04:00
Colin Kuebler f2e9942734
Merge pull request #1128 from KTannenberg/patch-1
fix path to mosquitto.conf
2024-04-15 11:33:41 -04:00
Klaus Tannenberg e085d96502
fix path to mosquitto.conf 2024-04-04 21:50:05 +01:00
Colin Kuebler 771992a8d1
Merge pull request #918 from bj0rky/patch-1
Update start_flash.sh
2023-11-06 16:44:09 -05:00
Colin Kuebler 8f463ca4d4
Merge pull request #1093 from si458/patch-1
use I not S for ping IP
2023-11-06 16:43:07 -05:00
Colin Kuebler 7c0a2e1871
Merge pull request #1103 from sonny-chen/mosquitto-conf-fix
fix: mosquitto only listens on localhost when started without a conf file
2023-11-06 16:40:21 -05:00
Colin Kuebler ed7fa9ad16
Merge pull request #1107 from phavekes/patch-1
Add tput (ncursus)
2023-11-06 16:34:08 -05:00
Colin Kuebler 17e5021488
Merge pull request #890 from C0rn3j/master
Arch Linux support for install_prereq.sh
2023-11-06 16:32:17 -05:00
Peter Havekes 4e1c5802c9
Add tput (ncursus)
The alpine docker image has no "tput" command. That comes with the ncurses package.
2023-09-28 11:52:35 +02:00
Sonny 77af648589 fix: mosquitto only listens on localhost when started without a conf file
Signed-off-by: Sonny
2023-09-20 10:22:34 +08:00
Simon Smith 096e4c473a
use I not S for IP 2023-04-13 14:44:53 +01:00
Colin Kuebler b361927102
Merge pull request #1024 from agios/hotfix
Fix TypeError
2022-09-13 16:45:30 -04:00
Colin Kuebler dc451e27e5
Merge pull request #1063 from lynxis/master
oui: add CC8CBF (Tuya Smart Inc.) to nonesp
2022-09-13 16:43:43 -04:00
Alexander Couzens 1f909de890 oui: add CC8CBF (Tuya Smart Inc.) to nonesp
Found on NOUS Smart Socket A1 (MFG 01/2022).
New versions of the A1 are using a BK7231N instead of an esp8266.
2022-09-09 03:39:47 +02:00
Martin Rys 253a525ee6 Fix stop/restart of NetworkManager by switching to systemctl 2022-08-01 13:15:44 +02:00
Martin 6645e7ebbf
Merge branch 'development' into master 2022-08-01 12:11:25 +02:00
Alexandros Giouzenis 8f29f72b55 Fix TypeError 2022-01-13 08:53:06 +02:00
Colin Kuebler c89bba280e
Merge pull request #988 from sarumpaet/development
fix detecting used ports in Docker
2021-11-17 11:53:34 -05:00
Colin Kuebler cbdccb772a
Merge pull request #943 from NickVeld/old_screen_logging
screen<=4.5 generates smarthack-*.log now too
2021-11-13 15:06:21 -05:00
Colin Kuebler e0de04f3bc
Merge pull request #945 from NickVeld/ubuntu_mate_18_test_info
README.md: new tested specification (Ubuntu Mate 18 i386)
2021-11-13 15:05:05 -05:00
Colin Kuebler a83a9d3683
Merge pull request #994 from WereCatf/master
Try alternate NetworkManager-naming
2021-11-13 14:20:57 -05:00
WereCatf 03e9da38df Try alternate NetworkManager-naming
'service network-manager' may fail on newer Linux-distros
due to the service actually being called 'NetworkManager'
now. This patch tries both and warns the user, if it still
fails.
2021-10-10 12:41:13 +03:00
sarumpaet f905ca8716 fix detecting used ports in Docker
Processes blocking ports that run on the host are not visible
within a Docker container. This was misdetected as the port being
available. Print an error and abort instead.
2021-09-23 14:53:59 +02:00
Colin Kuebler c2cf66cc3e
Merge pull request #965 from schinckel/master
Force ping to use a specific address.
2021-07-27 10:05:01 -04:00
Matthew Schinckel eaaa1e71cc Force ping to use a specific address.
This helps when there are multiple networks available on the device running
tuya-convert, as it will force the pings to go via the interface that the
device will convert to, not the default interface.
2021-07-27 11:23:05 +01:00
Colin Kuebler 6281d83756
Merge pull request #915 from Cyber1000/development
changed docker-image to alpine
2021-05-01 21:44:20 -04:00
NickVeld 63746fb6a3
README.md: new tested specification 2021-04-28 07:13:53 +03:00
NickVeld 458faf3d55 screen<=4.5 generates smarthack-*.log now too 2021-04-26 03:03:15 -04:00
bj0rky 8f218ec2ed
Update start_flash.sh
Tasmota and ESPurna version numbers
2021-02-17 20:25:32 +01:00
Harald Heigl badbe6b080 changed docker-image to alpine 2021-01-31 01:57:24 +01:00
Martin Rys 774a8ffd9a remove util-linux as it is part of a base system 2021-01-27 00:24:43 +01:00
Martin c8f69ac9df
Merge branch 'development' into master 2021-01-26 23:55:26 +01:00
Colin Kuebler 61ba060b85
Release v2.4.5 2021-01-26 17:40:28 -05:00
Colin Kuebler 0bb23695ce
Merge pull request #911 from kueblc/dr-tuya
Attempt to automatically diagnose common issues
2021-01-26 17:39:18 -05:00
Colin Kuebler 1cc2bdc216 Attempt to automatically diagnose common issues 2021-01-26 17:08:18 -05:00
Martin Rys 8a098b7baa Add note about network manager 2021-01-04 12:26:29 +01:00
Martin Rys d82f5281a7 install pip modules for root instead of current user 2021-01-04 11:34:49 +01:00
Martin Rys d96b38b786 add Arch support and tidy up 2021-01-04 11:25:23 +01:00
Colin Kuebler 869386c621
Merge pull request #868 from barbudor/update-tasmota-v920
Upgrade tasmota to tasmota-lite.bin v9.2.0
2020-12-20 11:12:48 -05:00
Barbudor dce3b8fa6f Upgrade tasmota to tasmota-lite.bin v9.2.0 2020-12-17 21:39:35 +01:00
Colin Kuebler 554277bcfc
Merge pull request #844 from ct-Open-Source/kueblc-readme-updates
README Updates
2020-12-10 21:12:02 -05:00
Colin Kuebler 2e821221f4
Merge pull request #849 from rpavlik/patch-1
Update start_flash.sh
2020-12-10 21:11:36 -05:00
Colin Kuebler 2039c2fabc
Pedantic whitespace tweaks
Co-authored-by: Odd Stråbø <oddstr13@openshell.no>
2020-12-10 21:10:37 -05:00
Ryan A. Pavlik da88d9a255
Update start_flash.sh
Mention an apparently common case of too-new firmware.
Took me a while to find my device mentioned on that list,
so I figured it might be useful.
2020-12-07 12:12:11 -06:00
Colin Kuebler c64092f683
Update warnings about Tuya's firmware patches 2020-12-02 10:37:56 -05:00
Colin Kuebler 7fd2156401
Remove dead link 2020-12-02 10:27:21 -05:00
Colin Kuebler 71aaa1fb18
Merge pull request #821 from lukavia/master
Minor fixes for docker execution. Fixes #691
2020-12-02 09:46:56 -05:00
Anton Avramov 6781b42d05 Fix dnsmasq tries to listen on localhost by default 2020-11-19 12:14:51 -05:00
Anton Avramov 587a2478b5 Add rkfill package so it could be installed in docker image 2020-11-19 12:14:03 -05:00
Colin Kuebler 94acc3bb02
Release v2.4.4 2020-06-20 13:51:36 -04:00
Colin Kuebler 87e300964c
Merge pull request #670 from fabsenet/patch-1
works on PI 4 B
2020-06-20 13:45:12 -04:00
Colin Kuebler 554b75db17
Merge branch 'development' into patch-1 2020-06-20 13:44:49 -04:00
Fabian Wetzel cb1aa96d95
works on PI 4 B
I successfully flashed 4 gosund sp111 using a PI 4 B, just wanted to let you guys know! thanks for this script!
2020-06-15 18:04:18 +02:00
Colin Kuebler 99b79e062d
Merge pull request #657 from olafz/tested_with_buster
Tested with Raspberry Pi OS Buster
2020-06-13 09:30:27 -04:00
Olaf van Zandwijk c911af077d
Tested with Raspberry Pi OS Buster 2020-06-01 11:57:44 +02:00
Colin Kuebler 101bc199cb
Merge pull request #642 from barbudor/tasmota-doc-update_dev
Tasmota: Advise not to use `tasmota-minimal.bin`
2020-05-24 17:17:16 -04:00
Barbudor dcda70cf28 Tasmota: Advise not to use `tasmota-minimal.bin` 2020-05-24 22:42:30 +02:00
Colin Kuebler 083dc2d58f Ensure wifi is not blocked by rfkill 2020-05-22 17:09:52 -04:00
Colin Kuebler 14b930ddca Remove -H option from ss call, not available in older ss. Fixes #622 2020-05-21 23:21:46 -04:00
Colin Kuebler b3fdf26b76
Merge pull request #584 from gotbadger/pi-zero-w
Update README.md
2020-05-21 14:12:32 -04:00
Colin Kuebler 7752f941b6 Follow links, closes #631 2020-05-21 13:08:21 -04:00
Colin Kuebler a9602a293b Merge branch 'development' of github.com:ct-Open-Source/tuya-convert into development 2020-05-16 00:20:44 -04:00
Philip Hayton fbc411604d
Update README.md 2020-04-10 16:54:21 +01:00
Colin Kuebler bb494835d1
Merge pull request #568 from bessarabov/patch-1
Removed 404 link from README.md
2020-03-13 11:12:14 -04:00
Ivan Bessarabov ef8b0935ef Removed 404 link from README.md 2020-03-13 08:40:18 +03:00
Colin Kuebler d031030b74 Check that ufw exists before checking if it is running 2020-02-29 00:30:48 -05:00
Colin Kuebler 3cefffa7af Add warning comment to deter users from changing hardcoded IP during debugging 2020-02-29 00:30:07 -05:00
21 changed files with 312 additions and 73 deletions

6
.env-template Normal file
View File

@ -0,0 +1,6 @@
#Attention: "host" means your computer where you are running docker on
WLAN=wlan0 #must match the name of your wlan-interface on your host, you may find it with ifconfig
AP=vtrust-flash #the name of the created AP, can be anything you want
GATEWAY=10.42.42.1 #gateway address, leave it here
LOCALBACKUPDIR=./data/backups #location on your host where you want to store backuos of the old firmware & logs

3
.gitignore vendored
View File

@ -109,8 +109,9 @@ node_modules/
device-info.txt
scripts/smartconfig/package-lock.json
# firmware backups directory
# firmware backups directory and data-file
backups/
data
# flag files
eula_accepted

View File

@ -1,13 +1,13 @@
FROM phusion/baseimage:master
FROM alpine:3.13
RUN apt-get update && apt-get install -y sudo iproute2 iputils-ping
RUN apk add --update bash git iw dnsmasq hostapd screen curl py3-pip py3-wheel python3-dev mosquitto haveged net-tools openssl openssl-dev gcc musl-dev linux-headers sudo coreutils grep iproute2 ncurses
RUN echo '* libraries/restart-without-asking boolean true' | sudo debconf-set-selections
RUN python3 -m pip install --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
COPY docker/bin /usr/bin/
COPY . /usr/bin/tuya-convert
RUN cd /usr/bin/tuya-convert && ./install_prereq.sh
WORKDIR "/usr/bin/tuya-convert"
RUN mkdir -p /etc/service/tuya && cd /etc/service/tuya && ln -s /usr/bin/config.sh run
ENTRYPOINT ["tuya-start"]

View File

@ -5,14 +5,14 @@ A Chinese company named Tuya offers a free-to-brand turnkey smart home solution
Aside from that, they claim their cloud solution has 'military grade security'. Michael Steigerwald, founder of the German IT security startup VTRUST, was able to disprove this claim and presented his results in the "Smart home - Smart hack" talk at 35C3 in Leipzig: https://media.ccc.de/v/35c3-9723-smart_home_-_smart_hack
In the following days, VTRUST and the German tech magazine c't decided to work together. Since reflashing devices using the ESP8266/85 is widespread among DIY smart home enthusiasts, we wanted to provide an easy way for everyone to free their devices from the cloud without the need for a soldering iron.
In the following days, VTRUST and the German tech magazine c't decided to work together. Since reflashing devices using the ESP8266/85 is widespread among DIY smart home enthusiasts, we wanted to provide an easy way for everyone to free their devices from the cloud without the need for a soldering iron.
Please make sure to visit VTRUST (https://www.vtrust.de/), since the hack is their work.
## 🚨WARNING🚨
Please be sure that you understand what you're doing before using this software. Flashing an alternative firmware can lead to unexpected behavior and/or render the device unusable, so that it might be permanently damaged (highly unlikely) or require soldering a serial connection to the processor in order to reflash it (likely).
Please be sure that you understand what you're doing before using this software. Flashing an alternative firmware can lead to unexpected behavior and/or render the device unusable, so that it might be permanently damaged (highly unlikely) or require soldering a serial connection to the processor in order to reflash it (likely).
### ⚠️ Be aware that you use this software at your own risk so neither VTRUST nor c't/heise can be held accountable for any damage done or loss of functionality. ⚠️
### ⚠️ Be aware that you use this software at your own risk so neither VTRUST nor c't/heise can be held accountable for any damage done or loss of functionality. ⚠️
TUYA-CONVERT only provides with the means to backup the original and flash an alternative firmware. Please do not ask for hardware support for your favorite alternative firmware in this repository, rather open an issue in the corresponding repository.
@ -27,18 +27,24 @@ Since Tuya devices are spread around the world with likely a vast amount of diff
* Secondary wifi device (e.g. smartphone)
* Dependencies will be installed by `install_prereq.sh`
These scripts were tested in
These scripts were tested in
* Kali-Linux 2018.4 in VMWARE
* a Raspberry Pi 3B / 3B+ with Raspbian Stretch and its internal Wifi chip
* a Raspberry Pi 3B+ + USB-WIFI with this image from [here](https://www.offensive-security.com/kali-linux-arm-images/)
https://images.offensive-security.com/arm-images/kali-linux-2018.4a-rpi3-nexmon-64.img.xz
* Ubuntu 18.04.3 64Bit in VirtualBox on Win10 with a [cheap RTL8188CU Wifi Adapter](http://s.click.aliexpress.com/e/KrKIoPdI) connected to the VM
* a Raspberry Pi Zero W with Rasbian
* a Raspberry Pi 3B / 3B+ / 4B with Raspbian Stretch and its internal Wifi chip
* a Raspberry Pi 3B / 3B+ Raspberry Pi OS Buster (previously called Raspbian) and its internal Wifi chip
* a Raspberry Pi 3B+ + USB-WIFI with an image from [here](https://www.offensive-security.com/kali-linux-arm-images/)
* Ubuntu 18.04.3 64Bit in VirtualBox on Win10 with a cheap RTL8188CU Wifi Adapter connected to the VM
* Ubuntu Mate 18.04.5 32bit in VirtualBox on Win 10 with cheap Ralink 802.11n WLAN (MediaTek RT5370) WiFi Adapter connected to VM
Any Linux with a Wifi adapter which can act as an Access Point should also work. Please note that we have tested the Raspberry Pi with clean installations only. If you use your Raspberry Pi for anything else, we recommend using another SD card with a clean installation.
## PROCEDURE
On January 28th, 2019, Tuya started [distributing a patch](https://www.heise.de/newsticker/meldung/Smart-Home-Hack-Tuya-veroeffentlicht-Sicherheitsupdate-4292028.html) that prevented older versions of tuya-convert from completing successfully. We have since developed a work around to enable OTA flashing once again, but there is always the possibility that Tuya will respond with yet another patch. To ensure the best chance of success, **do not connect your device with the official app** as it may automatically update the device, preventing you from flashing with tuya-convert. It is up to the individual brands to update their firmware, so some devices may be affected sooner than others.
On January 28th, 2019, Tuya started [distributing a patch](https://www.heise.de/newsticker/meldung/Smart-Home-Hack-Tuya-veroeffentlicht-Sicherheitsupdate-4292028.html) that prevented older versions of tuya-convert from completing successfully. We have since developed a work around to enable OTA flashing on some newer devices, but Tuya has since released [yet another patch](https://github.com/ct-Open-Source/tuya-convert/issues/483).
To ensure the best chance of success, **do not connect your device with the official app** as it may automatically update the device, preventing you from flashing with tuya-convert. It is up to the individual brands to update their firmware, so some devices may be affected sooner than others.
Unfortunately many devices have already been shipping with the new patched firmware, evident by a PSK ID beginning with 02 in smarthack-psk.log. There is no workaround at this time. Additionally, manufacturers have been silently switching from the ESP82xx based modules to other chipsets, making it impossible to install alternative ESP firmware on these devices.
### INSTALLATION
# git clone https://github.com/ct-Open-Source/tuya-convert
@ -49,7 +55,7 @@ On January 28th, 2019, Tuya started [distributing a patch](https://www.heise.de/
BE SURE THE FIRMWARE FITS YOUR DEVICE!
1. Place your binary file in the `/files/` directory or use one of the included firmware images.
Currently a [Tasmota](https://github.com/arendst/Tasmota) `tasmota-wifiman.bin` build is included in the Tuya-Convert package. You can update to the [current maintenance release](http://thehackbox.org/tasmota) via OTA after the flashing process completes successfully. The included binary does not have any specific hardware configured. Once flashed using Tuya-Convert you will need to configure your device(s) properly. Please note that while we include this firmware for your convenience, we are not affiliated with the Tasmota project and cannot provide support for post installation issues. Please refer to the [Tasmota project](https://github.com/arendst/Tasmota) and [its documentation](http://tasmota.com) for configuration and support.
Currently a [Tasmota](https://github.com/arendst/Tasmota) `tasmota-lite.bin` build is included in the Tuya-Convert package. You can easily update to the [current maintenance release](http://thehackbox.org/tasmota) via OTA **after** the flashing process completes successfully. The included binary does not have any specific hardware configured. Once flashed using Tuya-Convert you will need to configure your device(s) properly. Please note that while we include this firmware for your convenience, we are not affiliated with the Tasmota project and cannot provide support for post installation issues. Please refer to the [Tasmota project](https://github.com/arendst/Tasmota) and [its documentation](http://tasmota.com) for configuration and support. **IMPORTANT:** If you still want to update the tasmota binary before using Tuya-Convert, always pickup `tasmota-lite.bin`. **Never ever** use `tasmota-minimal.bin` as you will brick your device.
An ESPurna [1.13.5](https://github.com/xoseperez/espurna/releases/tag/1.13.5) binary is also included (`espurna-base.bin`). Like before, the binary included does not have any specific hardware defined. Once flashed using Tuya-Convert you can update to the device-specific version via any of the means that ESPurna provides (OTA, web interface update, update via telnet or MQTT). Please refer to the [ESPurna project page](http://espurna.io) for more info and support.
@ -68,7 +74,7 @@ BE SURE THE FIRMWARE FITS YOUR DEVICE!
If you flashed the included Tasmota firmware file, it will broadcast a `tasmota-xxxx` access point (AP) when the device boots. Connect to this AP and open the browser to 192.168.4.1 to configure the device's Wi-Fi credentials. When entering the Wi-Fi password, click the checkbox to view the password you enter to ensure that it is correct and that your mobile device has not inadvertently capitalized the first letter if it is supposed to be lower case nor autocorrected what you entered. ~~Double~~ **Triple check the Wi-Fi credentials** before clicking **Save** to apply the settings.
If you flashed the included ESPurna firmware file, the procedure will be very similar. The device will broadcast a `ESPURNA-XXXXXX` access point. You will have to connect to it using the default password: `fibonacci`. Once connected open the browser to 192.168.4.1 and follow the initial configuration instructions. Then go to the WIFI tab and configure your home WiFi connection (remember to save) or go to the ADMIN tab to upgrade the firmware to the device-specific image.
If you flashed the included ESPurna firmware file, the procedure will be very similar. The device will broadcast a `ESPURNA-XXXXXX` access point. You will have to connect to it using the default password: `fibonacci`. Once connected open the browser to 192.168.4.1 and follow the initial configuration instructions. Then go to the WIFI tab and configure your home WiFi connection (remember to save) or go to the ADMIN tab to upgrade the firmware to the device-specific image.
## USING DOCKER
You may want to use a docker image instead. Advantage of this solution: You don't have to install anything on your host (except docker), everything goes into the docker image.
@ -78,26 +84,24 @@ Requirements:
* docker is installed
* docker-compose is installed
Create docker image:
Preparations:
* git clone https://github.com/ct-Open-Source/tuya-convert
* cd tuya-convert
* docker build -t tuya:latest .
* if you have already cloned this repo just cd into the directory and execute `git pull`
* cp .env-template .env
* adjust the created .env-file, it contains usage information as comments
Setup docker-compose:
* copy docker/docker-compose.sample.yml to a new folder you created, the file should be named docker-compose.yml
* you may adjust this docker-compose.yml, if necessary:
* environment-variables may be different, for example network-adapter may be different from wlan0
* adjust the volume folder, where you want your backups stored
Building and running your container:
* `docker-compose build && docker-compose run --rm tuya`
* This directly starts into tuya. If you press ctrl+break or exit tuya after flashing, your container is closed and deleted
Run the image:
* go into the folder you copied docker-compose.yml
* docker-compose up -d
* docker-compose exec tuya start
* tuya-convert now starts within docker
Stop the image:
* docker-compose exec tuya stop
* docker-compose down
Troubleshooting:
* Q: Where are my logs after flashing? A: The folder can be adjusted in .env with LOCALBACKUPDIR, the path here may be relative or absolute
* Q: I don't want that my container is deleted after running tuya, I need this for troubleshooting! How do I accomplish this? A: Just remove --rm from `docker-compose run --rm tuya`
* Q: I want to start the container, but instead of starting tuya immediately I want to get into bash. Is this possible? A: Yes just start the container with `docker-compose run --entrypoint bash tuya`.
* Q: I want to rebuild my docker-image, even if there are no changes. Is this possible? A: Just start `docker-compose build --no-cache` instead of `docker-compose build`! Don't do this all the time, this is a time consuming process ...
* Q: I can't connect to my USB, PCI, ... network card. How do I get this working? A: You may have an error in your .env-File. The WLAN-variable should reflect the name of your network interface on your host. Execute ifconfig and look through your interfaces.
* Q: I can't get an IP-address and or connection on my phone, what's the problem? A: You may look into smarthack-wifi.log (location is set in .env with LOCALBACKUPDIR) or possible stop your firewall (e.g. NixOS seems to have a problem here). It may be a problem with a wrongly set network interface (see previous question)
## CONTRIBUTING
@ -115,4 +119,3 @@ You can also give back by providing or improving documentation, tutorials, issue
- [TuyAPI](https://github.com/codetheweb/tuyapi) NPM library for LAN control of Tuya devices with stock firmware
- [TuyOTA](https://github.com/SynAckFin/TuyOTA) Perl based Tuya flashing script using a similar strategy
- [MockTuyaCloud](https://github.com/kueblc/mocktuyacloud) Framework replicating much of the Tuya cloud functionality

12
docker-compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: '3'
services:
tuya:
build: .
privileged: true
network_mode: "host"
environment:
WLAN: ${WLAN}
AP: ${AP}
GATEWAY: ${GATEWAY}
volumes:
- $LOCALBACKUPDIR:/usr/bin/tuya-convert/backups

View File

@ -1,2 +0,0 @@
#!/bin/bash
pkill -SIGINT -f start_flash.sh

View File

@ -1,3 +1,3 @@
#!/bin/bash
cd /usr/bin/tuya-convert
config-tuya.sh
./start_flash.sh

View File

@ -1,12 +0,0 @@
version: '3'
services:
tuya:
image: tuya:latest
privileged: true
network_mode: "host"
environment:
- WLAN=wlan0
- AP=vtrust-flash
- GATEWAY=10.42.42.1
volumes:
- ./data/backups:/usr/bin/tuya-convert/backups

Binary file not shown.

View File

@ -1,10 +1,36 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail
set -e
debianInstall() {
sudo apt-get update
sudo apt-get install -y git iw dnsmasq rfkill hostapd screen curl build-essential python3-pip python3-setuptools python3-wheel python3-dev mosquitto haveged net-tools libssl-dev iproute2 iputils-ping
sudo python3 -m pip install --user --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
}
sudo apt-get update
sudo apt-get install -y git iw dnsmasq hostapd screen curl build-essential python3-pip python3-setuptools python3-wheel python3-dev mosquitto haveged net-tools libssl-dev
archInstall() {
sudo pacman -S --needed git iw dnsmasq hostapd screen curl python-pip python-wheel python-pycryptodomex python-paho-mqtt python-tornado mosquitto haveged net-tools openssl
sudo python -m pip install --user --upgrade git+https://github.com/drbild/sslpsk.git
}
sudo -H python3 -m pip install --upgrade paho-mqtt tornado git+https://github.com/drbild/sslpsk.git pycryptodomex
if [[ -e /etc/os-release ]]; then
source /etc/os-release
else
echo "/etc/os-release not found! Assuming debian-based system, but this will likely fail!"
ID=debian
fi
if [[ ${ID} == 'debian' ]] || [[ ${ID_LIKE-} == 'debian' ]]; then
debianInstall
elif [[ ${ID} == 'arch' ]] || [[ ${ID_LIKE-} == 'arch' ]]; then
archInstall
else
if [[ -n ${ID_LIKE-} ]]; then
printID="${ID}/${ID_LIKE}"
else
printID="${ID}"
fi
echo "/etc/os-release found but distribution ${printID} is not explicitly supported. Assuming debian-based system, but this will likely fail!"
debianInstall
fi
echo "Ready to start upgrade"

67
scripts/dr_tuya.sh Executable file
View File

@ -0,0 +1,67 @@
#!/bin/bash
NON_ESP_WARNING="WARNING: it appears this device does not use an ESP82xx and therefore cannot install ESP based firmware"
get_macs_from_wifi_log () {
grep AP-STA-CONNECTED smarthack-wifi.log |
cut -d ' ' -f3 |
sort | uniq
}
get_ouis_from_wifi_log () {
get_macs_from_wifi_log |
tr -d : | grep -Po "^.{6}"
}
psk_02 () {
grep -q "ID: 02" smarthack-psk.log
}
web_non_esp () {
grep -q "$NON_ESP_WARNING" smarthack-web.log
}
udp_non_esp () {
grep -q "$NON_ESP_WARNING" smarthack-udp.log
}
esp_oui () {
get_ouis_from_wifi_log | grep -iqf- oui/esp.txt
}
non_esp_oui () {
get_ouis_from_wifi_log | grep -iqf- oui/nonesp.txt
}
check_for_common_issues () {
if psk_02; then
echo "Your device's firmware is too new."
echo "Tuya patched the PSK vulnerability that we use to establish a connection."
echo "You might still be able to flash this device over serial."
echo "For more information and to follow progress on solving this issue see:"
echo "https://github.com/ct-Open-Source/tuya-convert/wiki/Collaboration-document-for-PSK-Identity-02"
exit 1
fi
if web_non_esp || udp_non_esp || non_esp_oui; then
echo "Your device does not use an ESP82xx."
echo "This means you cannot flash custom ESP firmware even over serial."
exit 1
fi
if esp_oui; then
echo "An ESP82xx based device connected according to your wifi log."
echo "If this is the device you are trying to flash, another issue may be preventing it from flashing."
echo "Otherwise, it could be that the device does not use an ESP82xx or it did not connect."
else
echo "No ESP82xx based devices connected according to your wifi log."
echo "Here is a list of all the MAC addresses that connected:"
get_macs_from_wifi_log
echo
echo "If you see your IoT device in this list, it is not an ESP82xx based device."
echo "Otherwise, another issue may be preventing it from connecting."
fi
echo "For additional information, check the *.log files inside the scripts folder."
echo "Please include these logs when opening a new issue on our GitHub issue tracker."
}
check_for_common_issues

View File

@ -13,7 +13,7 @@ while true; do
# get short name
filename=$(basename "$file")
# skip files too large or too small
filesize=$(stat -c%s "$file")
filesize=$(stat -Lc%s "$file")
[[ "$filesize" -gt 0x1000 && "$filesize" -le 0x80000 ]] || continue
# skip files without magic byte
[[ $(head -c 1 "$file") == "$MAGIC" ]] || continue

2
scripts/mosquitto.conf Normal file
View File

@ -0,0 +1,2 @@
allow_anonymous true
listener 1883

21
scripts/old_screen_with_log.sh Executable file
View File

@ -0,0 +1,21 @@
# Run screen with a custom .screenrc that defines the name of "logfile"
screen_minor=${1}
screen_logfile_name=${2}
screen_other_options=${@:3}
if [ "$screen_minor" -gt 5 ]; then
echo "Info: you have the modern enough version" \
"to use the \"-Logfile\" flag of \"screen\""
elif [ "$screen_minor" -eq 5 ]; then
screen_with_log="sudo screen -L"
else
screen_with_log="sudo screen -L -t"
fi
echo "logfile ${screen_logfile_name}" > ${screen_logfile_name}.screenrc
${screen_with_log} ${screen_logfile_name} \
-c ${screen_logfile_name}.screenrc ${screen_other_options}
rm ${screen_logfile_name}.screenrc

70
scripts/oui/esp.txt Normal file
View File

@ -0,0 +1,70 @@
# "Espressif Inc." OUIs
# updated Jan 26 2021
083AF2
0CDC7E
10521C
18FE34
240AC4
2462AB
246F28
24A160
24B2DE
2C3AE8
2CF432
30AEA4
3C6105
3C71BF
40F520
483FDA
4C11AE
4C7525
500291
545AA6
5CCF7F
600194
6055F9
68C63A
70039F
7C9EBD
7CDFA1
807D3A
840D8E
84CCA8
84F3EB
8CAAB5
8CCE4E
9097D5
943CC6
94B97E
98CDAC
98F4AB
9C9C1F
A020A6
A0764E
A47B9D
A4CF12
A4E57C
A8032A
AC67B2
ACD074
B4E62D
B8F009
BCDDC2
BCFF4D
C44F33
C45BBE
C4DD57
C82B96
CC50E3
D8A01D
D8BFC0
D8F15B
DC4F22
E09806
E0E2E6
E868E7
E8DB84
ECFABC
F008D1
F4CFA2
FCF5C4

18
scripts/oui/nonesp.txt Normal file
View File

@ -0,0 +1,18 @@
# Known unsupported OUIs including
# "Tuya (HK) Limietd"
# "Tuya Smart Inc."
# "Beijing Winner Microelectronics Ltd"
# updated Jan 26 2021
000D8A
000F89
10D561
1869D8
286DCD
68572D
708976
807484
84E342
D4A651
DC446D
E078A3
CC8CBF

View File

@ -69,7 +69,7 @@ class PskFrontend():
self.sessions.append((ssl_sock, s2))
except ssl.SSLError as e:
print("could not establish sslpsk socket:", e)
if "NO_SHARED_CIPHER" in e.reason or "WRONG_VERSION_NUMBER" in e.reason or "WRONG_SSL_VERSION" in e.reason:
if e and ("NO_SHARED_CIPHER" in e.reason or "WRONG_VERSION_NUMBER" in e.reason or "WRONG_SSL_VERSION" in e.reason):
print("don't panic this is probably just your phone!")
except Exception as e:
print(e)

View File

@ -16,6 +16,8 @@ version_check () {
}
setup () {
rfkill unblock wifi
wpa_supplicant_pid=$(pidof wpa_supplicant)
if [ -n "$wpa_supplicant_pid" ]; then
echo "Attempting to stop wpa_supplicant"
@ -24,7 +26,13 @@ setup () {
if test -d /etc/NetworkManager; then
echo "Stopping NetworkManager..."
sudo service network-manager stop
if ! sudo systemctl stop network-manager 2>/dev/null
then
if ! sudo systemctl stop NetworkManager 2>/dev/null
then
echo "** Failed to stop NetworkManager, AP may not work! **"
fi
fi
fi
echo "Configuring AP interface..."
@ -40,6 +48,7 @@ setup () {
--interface=$WLAN \
--bind-interfaces \
--listen-address=$GATEWAY \
--except-interface=lo \
--dhcp-range=10.42.42.10,10.42.42.40,12h \
--address=/#/$GATEWAY
@ -59,11 +68,16 @@ cleanup () {
if test -d /etc/NetworkManager; then
echo "Restarting NetworkManager..."
sudo service network-manager restart
if ! sudo systemctl restart network-manager 2>/dev/null
then
if ! sudo systemctl restart NetworkManager 2>/dev/null
then
echo "** Failed to restart NetworkManager: network may not be functional! **"
fi
fi
fi
}
version_check
trap cleanup EXIT
setup

View File

@ -67,7 +67,8 @@ check_port () {
port="$2"
reason="$3"
echo -n "Checking ${protocol^^} port $port... "
process_pid=$(sudo ss -Hlnp -A "$protocol" "sport = :$port" | grep -Po "(?<=pid=)(\d+)" | head -n1)
ss_output=$(sudo ss -lnp -A "$protocol" "sport = :$port")
process_pid=$(echo "$ss_output" | grep -Po "(?<=pid=)(\d+)" | head -n1)
if [ -n "$process_pid" ]; then
process_name=$(ps -p "$process_pid" -o comm=)
echo "Occupied by $process_name with PID $process_pid."
@ -98,6 +99,12 @@ check_port () {
sleep 1
fi
else
if [ $(echo "$ss_output" | wc -l) -gt 1 ]; then
echo "Occupied by unknown process."
echo "Port $port is needed to $reason"
echo "Aborting due to occupied port"
exit 1
fi
echo "Available."
fi
}
@ -107,7 +114,7 @@ check_firewall () {
echo "Attempting to stop firewalld.service"
echo "When done, enable with: ${bold}sudo systemctl start firewalld.service${normal}"
fi
if sudo ufw status | grep -qw active; then
if command -v ufw >/dev/null && sudo ufw status | grep -qw active; then
sudo ufw disable
echo "When done, enable with: ${bold}sudo ufw enable${normal}"
fi

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
bold=$(tput bold)
normal=$(tput sgr0)
. ./config.txt
@ -10,10 +10,8 @@ setup () {
screen_minor=$(screen --version | cut -d . -f 2)
if [ "$screen_minor" -gt 5 ]; then
screen_with_log="sudo screen -L -Logfile"
elif [ "$screen_minor" -eq 5 ]; then
screen_with_log="sudo screen -L"
else
screen_with_log="sudo screen -L -t"
screen_with_log="./old_screen_with_log.sh ${screen_minor}"
fi
echo "======================================================"
echo -n " Starting AP in a screen"
@ -26,7 +24,7 @@ setup () {
echo " Starting web server in a screen"
$screen_with_log smarthack-web.log -S smarthack-web -m -d ./fake-registration-server.py
echo " Starting Mosquitto in a screen"
$screen_with_log smarthack-mqtt.log -S smarthack-mqtt -m -d mosquitto -v
$screen_with_log smarthack-mqtt.log -S smarthack-mqtt -m -d mosquitto -v -c $PWD/mosquitto.conf
echo " Starting PSK frontend in a screen"
$screen_with_log smarthack-psk.log -S smarthack-psk -m -d ./psk-frontend.py -v
echo " Starting Tuya Discovery in a screen"
@ -69,13 +67,22 @@ while true; do
echo "Waiting for the device to install the intermediate firmware"
i=120
while ! ping -c 1 -W 1 -n 10.42.42.42 &> /dev/null; do
# !!! IMPORTANT !!!
# Did your device get an IP address other than 10.42.42.42?
# That is because it is not running the intermediate firmware
# The intermediate firmware will request 10.42.42.42
# Do NOT change this address!!!
# It will NOT make it install and will break this script
while ! ping -c 1 -W 1 -n 10.42.42.42 -I 10.42.42.1 &> /dev/null; do
printf .
if (( --i == 0 )); then
echo
echo "Device did not appear with the intermediate firmware"
echo "Check the *.log files in the scripts folder"
echo "Timed out while waiting for the device to (re)connect"
pkill -f smartconfig/main.py && echo "Stopping smart config"
echo "======================================================"
echo "Attempting to diagnose the issue..."
./dr_tuya.sh
echo "======================================================"
read -p "Do you want to try flashing another device? [y/N] " -n 1 -r
echo
[[ "$REPLY" =~ ^[Yy]$ ]] || break 2
@ -112,8 +119,8 @@ while true; do
echo "Ready to flash third party firmware!"
echo
echo "For your convenience, the following firmware images are already included in this repository:"
echo " Tasmota v8.1.0.2 (wifiman)"
echo " ESPurna 1.13.5 (base)"
echo " Tasmota v9.2.0 (wifiman)"
echo " ESPurna 1.5 (base)"
echo
echo "You can also provide your own image by placing it in the /files directory"
echo "Please ensure the firmware fits the device and includes the bootloader"
@ -127,4 +134,3 @@ while true; do
echo
[[ "$REPLY" =~ ^[Yy]$ ]] || break
done