Here is an alternative solution, based on the following "Fake Yoneda Lemma". It does not just hold for rings, but for all algebraic objects of a given type (with the same proof), see my answer here.
Let $R,S$ be finite rings. Assume that for all finite rings $T$ there is a bijection $\mathrm{Hom}(T,R) \cong \mathrm{Hom}(T,S)$; not assumed to be natural. Then there is an isomorphism of rings $R \cong S$.
Now, if $ R,R',S$ are finite rings with $R \times S \cong R' \times S$, then for all finite rings $T$ we obtain, using the universal property of products
$$\begin{align*} & \quad\,\,\mathrm{Hom}(T,R') \times \mathrm{Hom}(T,S) \\ & \cong \mathrm{Hom}(T,R' \times S) \\ & \cong \mathrm{Hom}(T,R \times S) \\ & \cong \mathrm{Hom}(T,R) \times \mathrm{Hom}(T,S).\end{align*}$$
But these are just finite sets. So if $\mathrm{Hom}(T,S)$ was non-empty, we could derive $\mathrm{Hom}(T,R') \cong \mathrm{Hom}(T,R)$ and apply the "Fake Yoneda Lemma" to deduce $R \cong R'$. (This is exactly how one can prove cancellation for finite groups, see Seirios' answer here.)
The problem is that the zero map $T \to S$ is not a ring homomorphism (unless $S=0$). So let us just switch the category and work with rngs instead! Since the forgetful functor $\mathbf{Ring} \to \mathbf{Rng}$ preserves products and the "Fake Yoneda Lemma" also holds for rngs, the above argument, using finite rngs $ T$ instead, gives us an isomorphism $R \cong R'$ in the category $\mathbf{Rng}$. Now, any surjective homomorphism $\varphi$ of rngs between rings automatically preserves the multipliactive unit (since $\varphi(1)$ is a unit for the image, hence for the whole ring, and units are unique). So we get $R \cong R'$ in $\mathbf{Ring}$.