Bellow algorithm is able to factor $n$ with probability at least $\frac{1}{2}$:
RSA-FACTOR(n, a, b)
comment: we are assuming that $ab=1\pmod {\phi(n)}$
write $ab - 1 = 2^sr$
choose $w$ at random such that $1\leq w \leq n-1$
$x= gcd(w, n)$
if $l<x<n$ then return $(x)$
comment: $x$ is a factor of $n$
$v=w^r \pmod n$
if $v=1 \pmod n$ then
then return ("failure")
while $v \ne 1 \pmod n$ do
$v_0=v$
$v =v^2 \pmod n$
if $v_0=-1 \pmod n$ then return ("failure")
else $x=gcd (v_0+ 1 , n )$
return $(x)$
This is an algorithm 5.10 in the page $204$ of "CRYPTOGRAPHY
THEORY AND PRACTICE" by DOUGLAS R. STINSON.