\(\left\{{}\begin{matrix}n_{Mg}=a\left(mol\right)\\n_{Al}=b\left(mol\right)\end{matrix}\right.\left(a,b>0\right)\\ Mg+2HCl\rightarrow MgCl_2+H_2\\ 2Al+6HCl\rightarrow2AlCl_3+3H_2\\ \Rightarrow\left\{{}\begin{matrix}24a+27b=6,45\\22,4a+3.22,4b=7,28\end{matrix}\right.\Leftrightarrow\left\{{}\begin{matrix}a=0,1\\b=0,15\end{matrix}\right.\\ \Rightarrow\left\{{}\begin{matrix}m_{Mg}=0,1.24=2,4\left(g\right)\\m_{Al}=0,15.27=4,05\left(g\right)\end{matrix}\right.\)